Hug Me (hugs) wrote in freebsd_users,
Hug Me

fun script

a friend who is working on learning bash 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:

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)

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.

How would you have written it?
  • Post a new comment


    default userpic