Bash: ASCII char to Decimal

# decimal to ASCII char
chr() {
  printf \\$(printf '%o' $1)

# ASCII char to decimal number
ord() {
  local c=$1
  [[ $c == '%' ]] && c='%%'
  printf '%d' "'$c"

# printalbe ASCII
for i in {33..126}; do
    echo -e "$(chr $i) \t $(ord $(chr $i))\n"

Related to: Python: Built-in Function range, ord, chr

Leave a Comment

Your email address will not be published. Required fields are marked *