C5 BASH IF

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



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.


_______________________________________________
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