[CentOS] C5 BASH IF

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

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.

----------------------------
NON WORKING first comparison

5 if $dir="law"   
6   then
7        www="law"
8        dir=${file:0:5}
9 else
10        www="www/s"
11 fi

Error message = /root/bin/.us: line 5: law=law: command not found

---------------------------------

WORKING first comparison

5 if [ $dir="law" ]
6   then
7        www="law"
8        dir=${file:0:5}
9 else
10        www="www/s"
11 fi

------------------------------------

NON-WORKING second comparison

15 if [ $file='law00.css' ]
16   then
17        file=$dir/$file
18        echo "css"
19 else   
20        file=$dir/$file\.php
21        echo "no css"
22 fi
23 #----------------------------

Every comparison in the second test, including wrong comparisons,
satisfy the test and caused the 'css' display.

When line 15 was changed to

	15 if [ $file='law00css' ]

everything continued to match including items with no 'css' in the file
name.


Baffled.

Are C5 BASH scripts restricted to only 1 IF comparison ?




-- 
Regards,

Paul.
England, EU.      Je suis Charlie.