Below script will give you the ascii value corresponding number
#!/bin/bash
printf “Please enter a value between 32 to 127(Range of ascii values): “
read VAL1
printf “$(printf “%o” $VAL1)n”
Let me explain this script. The script will take input from user in to VAL1 variable and pass it to printf command. printf “%o” $VAL1 will try to change the decimal value to octal. then this octal value is once again feed to the second printf as printf “octvaluen”. printf command have one option what ever followed after will be treated as octal which helps use to convert to ascii values. Want to print all the ascii values? Execute below script to do that #!/bin/bash
for i in {32..127}
do
printf “$(printf “%o” $i)n”
done
or just one single liner which will work in bash version 4 and above. printf “$(printf “%on” {32..127})” Please comment your thoughts on this.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018