read -p "Please input number: " num
while true
do
if [[ $num =~ ^[0-9]+$]];then
break
else
read -p "Nonumber,Please input number: " num
fi
done
read -p "Please input prefix: " prefix
while true
do
if [-z "$prefix"];then
echo "error prefix"
else
read -p "Please input prefix"
fi
done
1.符號總結
() 在子shell執行
(()) C 風格的數值比較,((1<2))
$(1+2) 和`1+2`一樣,叫命令替換:先執行裏面的命令,eg:touch $(data+%F)_file.txt
$((1+2)) 整數運算
{} 表示集合,eg:touch {1..2}
${} 表示變量
[] 條件測試:文件,整數,數值,字符串比較
[[]] 功能包含[]的功能,還支持正則比較:[[ =~ ]],~表示正則匹配
eg:[ -d /home -a -f /home/files ];echo $? 等價於
[[ -d /home && -f /home/files ]];echo $?
$[2**10] 整數運算,2的10次方
./1.sh 重要的執行權限 在子shell中執行
bash 1.sh 不需要執行權限 在子shell中執行
.1.sh 不需要執行權限,在當前shell中執行
source 1.sh 不需要執行權限 在當前shell中執行
注意:通常修改系統配置文件如:/etc/profile的PATH等變量後,使之在當前shell中生效
sh -n 1.sh 僅調試syntax error
sh -vx 1.sh 以調試的方式進行,查詢整個執行過程