LDP/LDP/guide/docbook/abs-guide/ascii.sh

47 lines
1.2 KiB
Bash
Raw Normal View History

2008-03-13 13:24:45 +00:00
#!/bin/bash
# ascii.sh
2008-11-23 22:43:47 +00:00
# ver. 0.2, reldate 26 Aug 2008
# Patched by ABS Guide author.
2008-03-13 13:24:45 +00:00
2008-11-23 22:43:47 +00:00
# Original script by Sebastian Arming.
2008-03-13 13:24:45 +00:00
# Used with permission (thanks!).
exec >ASCII.txt # Save stdout to file,
#+ as in the example scripts
#+ reassign-stdout.sh and upperconv.sh.
MAXNUM=256
COLUMNS=5
OCT=8
OCTSQU=64
LITTLESPACE=-3
BIGSPACE=-5
i=1 # Decimal counter
o=1 # Octal counter
2008-11-23 22:43:47 +00:00
while [ "$i" -lt "$MAXNUM" ]; do # We don't have to count past 400 octal.
2008-03-13 13:24:45 +00:00
paddi=" $i"
2008-11-23 22:43:47 +00:00
echo -n "${paddi: $BIGSPACE} " # Column spacing.
2008-03-13 13:24:45 +00:00
paddo="00$o"
2008-11-23 22:43:47 +00:00
# echo -ne "\\${paddo: $LITTLESPACE}" # Original.
echo -ne "\\0${paddo: $LITTLESPACE}" # Fixup.
# ^
2008-03-13 13:24:45 +00:00
echo -n " "
2008-11-23 22:43:47 +00:00
if (( i % $COLUMNS == 0)); then # New line.
2008-03-13 13:24:45 +00:00
echo
fi
((i++, o++))
2008-11-23 22:43:47 +00:00
# The octal notation for 8 is 10, and 64 decimal is 100 octal.
(( i % $OCT == 0)) && ((o+=2))
(( i % $OCTSQU == 0)) && ((o+=20))
2008-03-13 13:24:45 +00:00
done
2008-11-23 22:43:47 +00:00
exit $?
# Compare this script with the "pr-asc.sh" example.
# This one handles "unprintable" characters.
# Exercise:
# Rewrite this script to use decimal numbers, rather than octal.