- wc -l 統(tǒng)計有多少行
2.流程控制語句if
"if" 表達式 如果條件為真則執(zhí)行then后面的部分修械。
if ....; then
....
elif ....; then
....
else
....
fi
3.bash 取變量
在bash 的變量取出的時候:
$BASH = "$BASH" = "${BASH}"
但是要注意: "${BASH}" 的使用場景是比如"$BASHis a dog"
, 不能區(qū)分就應使用{}
括起來趾牧。
#! /bin/bash
if [ "${SHELL}" = "/bin/bash" ];then
echo "this is bash"
elif [ "${SHELL}" = "aa" ];then
echo "this is aa"
else
echo "this is not /bin/bash, but $SHELL"
fi
4.使用shellcheck.net 可以檢查shell的語法是否錯誤。
5.條件判斷中:
if [ $A="AA" ];then
......
注意到肯污,[ $A ]
中[]
與$A
需要有空格隔開翘单。