fun script

Mar 12, 2009 10:36

a friend who is working on learning shell script asked me to do this. Write a script which generates all the letters then reports back whether they are capital or lowercase. It took me a little bit of thinking to come up with one I must admit, but this is what I wrote:

X=101
until [ "$X" -ge 173 ] ; do
printf "\\$X" | grep [A-Z] > /dev/null && printf "\\$X is a capital letter \n" || printf "\\$X is a lowercase letter \n"
[ "$X" = "132" ] && X=140
X=$(echo "ibase=8;obase=8;$X+1"|bc)
done

I had to convert the numbers into octal for printf to display them and had to look up variables to get bc to use base 8. I thought it was just "base" but it uses input base and output base so ibase and obase.

this got me thinking.... What about base 1? every base starts with 0... so base 10 is 0-9, base 16 is 0-F base 2 is 0 and 1... but base 1? Using 0 wouldn't make any sense. for example... in base 1 the number 5 would be: 11111 not 00000 as a 0 would be the absence of a number.

What do you think and why?
Previous post Next post
Up