Home > OS >  Unicode char representations in BASH / shell: printf vs od
Unicode char representations in BASH / shell: printf vs od

Time:09-29

I have two correlated ‘why’not ‘how to’— questions:

Question 1

While printf and od produce same decimal, octal, and hex representations for ASCII characters —

ascii_char=A

printf "%d" "'$ascii_char"
65
echo -n $ascii_char | od -A n -t d1
   65
echo -n $ascii_char | od -A n -t u1
  65
printf "%o" "'$ascii_char"
101
echo -n $ascii_char | od -A n -t o1
 101
printf "%x" "'$ascii_char"
41
echo -n $ascii_char | od -A n -t x1
 41

why do they somehow not produce same representations for a Unicode char?

unicode_char=           
  • Related