bash shell中的命令替換,`cmd`或者$(cmd)。shell
bash shell中的變量賦值,直接name = var; (bash中的變量賦值不能中間有空格)bash
變量引用時,$name,若是name比較複雜,也能夠是${name}命令行
取消變量的設置,unset,unset namecmd
bash中的for循環方式:it
1) for i in 1 2 3 4 5for循環
do 變量
echo "$i----->$(uptime)"循環
done引用
也能夠寫爲程序
for i in $(seq 1 10)
for i in {1..10}
num="1 2 3 4"
for i in $num
2) for i in `ls ./*.tar.gz`
do
tar -zxvf $i >/dev/null
done
該方法也能夠拿到當前路徑下文件名並放在一個列表中。
for i in `ls -1`
3)sum=0
for (i=0; i<100; i++)
do
sum=$(expr $i \* 3+1)
echo sum
done
bash中$#表示命令行輸入的cmd參數的個數,$?表示上一個cmd的返回值。
exit_status=0
eval ${VCSBIN_DIR}/hvp_exe $cmd ${logout}
exit_status=$?
bash中寫一個子標籤,
usage()
{
echo "Usages: hvp command"
echo "To see commands, 'hvp help' "
}
bash中的case 。。。esac
case `uname` in
SunOS*)
;;
Linux*)
;;
esac
其中的兩個雙引號,表示其餘語言中的break.
bash中的if-else-fi
if []; then
elif []; then
fi
其中的判斷句,-f 存在某個文件;
-x 存在某個可執行文件;
x"${vcs_home}" = x ;判斷變量${vcs_home}是否被定義過。前邊加x,不然直接應用比較出錯。
if [ x"${vcs_home}" = x ]; then
fi
-a,條件與, -o,條件或, !條件非
exit(0) 正常運行程序並退出程序。
exit(1) 非正常運行程序致使退出程序。