對(duì)shell不熟,偶爾會(huì)現(xiàn)一些我無法理解的現(xiàn)象。此時(shí)該進(jìn)行debug了,可選的方法有:
a. echo變量的值
b. shell –x
此外,Remember that the shell spends a lot of its life substituting text.(http://linuxcommand.org/wss0100.php)例如,對(duì)于下面的程序:
a. echo變量的值
b. shell –x
此外,Remember that the shell spends a lot of its life substituting text.(http://linuxcommand.org/wss0100.php)例如,對(duì)于下面的程序:
if語句里的var變量經(jīng)替換后變?yōu)?if [ = "y" ],些時(shí)當(dāng)然會(huì)出錯(cuò)。hex108@Gentoo ~ $ cat test.sh #!/bin/sh var= if [ $var = "y" ] ;then echo "yes" fi
hex108@Gentoo ~ $ ./test.sh
./test.sh: line 3: [: =: unary operator expected
ps:現(xiàn)在寫腳本的時(shí)候傾向于使用perl,而較少使用shell ,因?yàn)閷?duì)于經(jīng)常使用的腳本,可能會(huì)經(jīng)常需要對(duì)它不停地進(jìn)行改進(jìn),慢慢的,程序越來越大,該考慮重構(gòu)了, 此時(shí)才會(huì)發(fā)現(xiàn)perl(python等“真正的”腳本語言)比shell相對(duì)來說更好重構(gòu)。