There are several reasons. a) not all shells understand -z. Specifically, csh doesn't. Also, command.com and cmd.exe don't understand it. People used to any of these would naturally gravitate towards the alternative solution.
b) your version actually is incorrect. Even with -z, $var still needs to be enclosed in quotes. Otherwise, your statement would expand to either no or multiple arguments depending on the value of var and the shell you are using. (empty var becomes no arg to -z) var= if [ -z ]; then (multiple words in var become multiple args to -z) var="this is a test" if [ -z this is a test ]; then (my shell, bash 3.2.39(1), handles var without quotes, but I don't think all versions do). > -----Original Message----- > From: Brian Debelius [mailto:bdebel...@intelesyscorp.com] > Sent: Wednesday, March 03, 2010 11:06 AM > To: bacula-users@lists.sourceforge.net; ca...@unknownlamer.org > Subject: [Bacula-users] Shell script question. > > Hi, > > Looking at Bacula scripts and other scripts, I see a test for an > empty string performed by adding an 'x' before the variable, and then > comparing this to another string that is just an 'x'. > > The shell test function has a -z string test that returns true if > the > string is empty. > > It appears to me that more people use the 'x' comparison. Is there a > technical reason why one would be preferable to the other? > > Why would you do this: > > if [ "x$var" = "x" ]; then > ... > fi > > Instead of this: > > if [ -z $var ]; then > ... > fi ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Bacula-users mailing list Bacula-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bacula-users