2011-08-16, 22:24(+02), Francky Leyn: [...] > VAR=FALSE > # some command line procesing, that can set VAR to "TRUE" > if [ $VAR = TRUE ]; then > ... > fi > > Must I effectively write that VAR=FALSE? > Or will the script work fine without?
Yes, you must write it, because bash may inherit a VAR variable from the environment like I said (especially when you consider that all uppercase variables are by convention reserved for environment variables). > Also, can't I write the test as > > if [ $VAR ]; then > ... > fi [...] No. That syntax is wrong. Valid syntaxes are: if [ "$VAR" != "" ] if [ -n "$VAR" ] if [ "$VAR" ] Or if you want to be extremely portable: if [ "" != "$VAR" ] or if [ "x$VAR" != x ] Personally, I prefer: var=false if ... var=true ... if "$var"; then ... fi -- Stephane