Archive:
Subtopics:
Comments disabled |
Wed, 12 Nov 2008
Flag variables in Bourne shell programs
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 fiOr 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. [ Addendum 20090107: some followup notes ]
[Other articles in category /prog] permanent link |