[CentOS] C5 BASH IF

Sat Feb 14 05:54:35 UTC 2015
Always Learning <centos at u64.u22.net>

On Fri, 2015-02-13 at 23:46 -0600, Les Mikesell wrote:

> 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.

Thanks for that.  I assumed if test 1 worked, so would test 2.

Have re-run test 2 with


> 16 if  [ $file = "law00css" ]
> 17   then
> 18        echo $file
> 19        echo "css"
> 20 else
> 21        echo "no css"
> 22 fi

and got

> + '[' law45p07a01 = law00css ']'
> + echo 'no css'
> no css
> + exit

which is correct (for the first time). It seems that following your
good advice and plonking spaces around the = has solved the problem.

Thank you very much. Now I can go to bed a satisfied person :-)

-- 
Regards,

Paul.
England, EU.      Je suis Charlie.