I wanted to output a string of all the ascii characters with the following commandfor i in `seq 32 127`; do printf %c $i; doneThe output of the above command is: 33333334444444444555555555566666666667777777777..............It's the first (from the left) digit of each number.Looking through this site I came across the answer to my problem How to print all printable ASCII chars in CLI?, however I still don't understand why my original snippet does not output the ascii characters as intended.
Printing decimal to ascii character, my command does not output as intended
bash;shell;character encoding;ascii
You can't directly print the ascii codes by using the printf %c $i like in C.You have to first convert the decimal value of i into its octal value and then you have to print it using using printf and putting \ in front of their respective octal values. To print A, you have to convert the decimal 65 into octal, i.e. 101, and then you have to print that octal value as:printf \101\nThis will print A.So you have to modify it to :for i in `seq 32 127`; do printf \\$(printf %o $i);done;But by using awk you can directly print like in C languageawk 'BEGIN{for(i=32;i<=127;i++)printf %c,i}';echo