0

I need to output a symbol using variable that contains code of that symbol.

I already understood that in my code example bash thinks that i'm giving it a string. So according to specificator it outputs "4".

symbolValue=41
printf '%c' $symbolValue

I expect outputing of "A" symbol in fixed code. Please help me with it.

Roma
  • 55
  • 8

1 Answers1

2

Could you please try the following.

symbolValue=41
echo "$symbolValue" | xxd -p -r
# OR
xxd -p -r <<< "$symbolValue"

From man xxd:

-p | -ps | -postscript | -plain

output in postscript continuous hexdump style. Also known as plain hexdump style.

-r | -revert

reverse operation: convert (or patch) hexdump into binary. If not writing to stdout, xxd writes into its output file without truncating it. Use the combination -r -p to read plain hexadecimal dumps without line number information and without a particular column layout. Additional Whitespace and line-breaks are allowed anywhere.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
  • It doesn't prints zero value of variable:( Actualy doesn't work with arguments like 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9 but works with 01, 02 , 03, ... – Roma Sep 09 '19 at 18:55