Reputation:
I am trying to input a character from the user and display the corresponding ascii value to the screen. This is my code. If there are any errors please rectify and post it.
echo Enter a character
read n
printf "%d" $n;
Error-: ./ascii.sh: line 3: printf: a: invalid number
Upvotes: 1
Views: 138
Reputation: 8031
You need to put a single quote before $n
:
echo Enter a character
read n
printf "%d" \'$n
You can also get rid of the echo
:
read -p 'Enter a character: ' n
printf "%d" \'$n
Upvotes: 1