Pejman Moghadam / Scripts

ASCII Characters in bash script

Public domain


#!/bin/bash

row=25

for i in $(seq 0 $row); do
  count=$i
  max=255
  while [ "$count" -le $max ]
  do
    DEC=$count
    HEX=$(echo "ibase=10;obase=16; $DEC" | bc)
    if [ "$DEC" -le "31" ] || [ "$DEC" -ge "127" -a "$DEC" -le "160" ]; then
      CHR="."
    else
      CHR="\x$HEX"
    fi
    if [ "$DEC" -ge "256" ]; then
      printf " .  .   . | " $DEC $HEX
    else
      printf "%3s%3s  $CHR | " $DEC $HEX
    fi
    let "count += $row"
    let "count += 1"
  done
  echo
done

BY: Pejman Moghadam
TAG: bash, bash-script, ascii
DATE: 2009-04-25 00:17:32


Pejman Moghadam / Scripts [ TXT ]