How to print an octal value's corresponding UTF-8 character in bash?

I expected printf %s '\<octal_character_value>' to do the trick, but it doesn't:

printf %s '\101'

Outputs:

\101

Solution 1:

Presumably you want %b. From help printf:

In addition to the standard format specifications described in printf(1),
printf interprets:

  %b    expand backslash escape sequences in the corresponding argument

And:

$ printf "%b\n" '\101'
A

I don't know if it works for Unicode characters in general.

Solution 2:

You can use Awk:

$ awk 'BEGIN {print "\107"}'
G

Or the awk Velour library:

$ velour -n 'print n_chr(+n_baseconv(107, 8, 10))'
G