shell小知識:
1.引用變量時需要加‘$’
2.shell的變量查看與刪除
set | grep 變量名 //查看設置的變量
unset 變量名 //刪除變量
3.shell中的單引號與雙引號區別
注:單引號原封不動的賦值給變量;雙引號取消空格的作用
4.反引號,將shell命令賦值給變量
5.read:讀入數據,賦值給變量
6.expr:對整數型變量進行算術運算
注:注意空格,\是轉義,取消*的特殊含義
if語句:
vim if.sh
#!/bin/bash //指定運行腳本的shell //腳本開始
#File: if.sh
echo 'Hello, how old are you?'
echo 'Please input your age:'
read age //讀入數據
if [ $age -eq 28 ]; then
echo "You're at the age of marriage!"
elif [ $age -gt 28 -a $age -lt 35 ]; then //判斷年齡在28到35之間
echo "You must go on a blind date now."
elif [ $age -lt 28 ]; then
echo "You're still young and good to learn!"
else
echo "Sorry, I don't kown your age!"
fi //腳本結束
chmod +x if.sh //賦予執行權限
./if.sh //腳本當前路徑下執行腳本