Today on the listserv there was question regarding a shell program that no longer worked when ported from Solaris to a Linux environment. My reply to this entry was (unsurprisingly): rewrite the whole thing in Perl and never look back to it any more.
Now today, by coincidence I guess, I'm finding more on the same topic on the internet.�
Markus Dominus entered the following today on his The Universe of Discourse site:
(Markus is a leading figure in the Perl world, author of many Perl modules and an excellent and entertaining speaker)
Flag variables in Bourne shell programs
Who the heck still programs in Bourne shell? Old farts like me, occasionally. Of course, almost every time I do I ask myself why I didn't write it in Perl. Well, maybe this will be of some value to some fart even older than me..Suppose you want to set a flag variable, and then later you want to test it. You probably do something like this:
if some condition; then
IS_NAKED=1
fi...
if [ "$IS_NAKED" == "1" ]; then
flag is set
else
flag is not set
fi
Or maybe you use ${IS_NAKED:-0} or some such instead of "$IN_NAKED". Whatever.Today I invented a different technique. Try this on instead:
IS_NAKED=false
if some condition; then
IS_NAKED=true
fi...
if $IS_NAKED; then
flag is set
else
flag is not set
fi
The arguments both for and against it seem to be obvious, so I won't make them.I have never seen this done before, but, as I concluded and R.J.B. Signes independently agreed, it is obvious once you see it.

What tools are on your Swiss Army knife?
No user commented on " Shell Programming? "
Follow-up comment rss or Leave a Trackback