Bacula-users

Re: [Bacula-users] Shell script question.

2010-03-03 14:23:01
Subject: Re: [Bacula-users] Shell script question.
From: Phil Stracchino <alaric AT metrocast DOT net>
To: bacula-users AT lists.sourceforge DOT net
Date: Wed, 03 Mar 2010 14:18:20 -0500
On 03/03/10 14:05, Brian Debelius wrote:
> 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

more properly:  if [ -z "$var" ]; then

> ...
> fi

I've never understood that one myself.  I've always put it down to
people who don't know about the -z operator or learned shell scripting
in an environment in which it was not available.


-- 
  Phil Stracchino, CDK#2     DoD#299792458     ICBM: 43.5607, -71.355
  alaric AT caerllewys DOT net   alaric AT metrocast DOT net   phil AT 
co.ordinate DOT org
         Renaissance Man, Unix ronin, Perl hacker, Free Stater
                 It's not the years, it's the mileage.

------------------------------------------------------------------------------
Download Intel&#174; 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 AT lists.sourceforge DOT net
https://lists.sourceforge.net/lists/listinfo/bacula-users