I have a command: printf "\x$(printf %x $char)".
When I write in console: char=65; printf "\x$(printf %x $char)"; the result is written letter A.
But when I run my script:
#!/bin/bash
char=65;
printf "\x$(printf %x $char)"
The result is written: \x41
I tried to write sudo before the command printf in the script and then the command works as expected. I need to find a solution without the need of using sudo.
By running
sh script.shyou accidentally run your script using dash instead of bash, whose builtinprintfdoes not support\xHHliterals.