linux腳本衆多,有bash、csh已經其他衆多的*sh。
在各個版本的sh中,用法有一些不同。
本次需求:獲取腳本的個數,如果不滿足制定個數,輸出信息並退出
bash寫法:
#!/bin/bash
if [[ $# < 1 ]]; then #或者是if [ $# -lt 1 ]; then
echo Please input which directory to be don
exit
fi
diris=$1
echo $diris
csh寫法:
#!/bin/csh
if($#argv < 2)then
echo Please input which directory to be don
exit
endif
diris=$1
echo $diris
bash相對於csh有太多的語法限制,而且格式有很多限制。
bash中對if後面的空格有強制要求,而csh沒有
bash中後面的表達式如果想要用變量,則必須要使用雙方括號,而csh不需要。