Re: C5 BASH IF

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Fri, Feb 13, 2015 at 11:26 PM, Always Learning <centos@xxxxxxxxxxx> wrote:
> Being new to some aspects of BASH, I tried to reduce the quantity of
> scripts by introducing a comparison test into an existing working
> script.
>
> The script refused to work until I placed [ ] around the actual test.
> The second test, in the same script, misfunctioned until I removed the
> [ ] around the second test.
>

I think you are missing some very basic concepts here.  First, the
shell likes to parse things separated by white space.  Second, [ is a
synonym for test which is a build-in version of /bin/test, so try 'man
test' for the syntax of tests.   And third, you generally should use
double quotes around variables in tests so they continue to exist as
an empty string if the variable happens to not be set.

-- 
   Les Mikesell
      lesmikesell@xxxxxxxxx
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos




[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux