if

  1. if [ ! -d /root ]
  2. then
  3. echo "这不是目录,请重新输入"
  4. continue
  5. else
  6. echo "这是目录"
  7. break
  8. fi

for

  1. for循环用法
  2. for i in 1 3 5 7
  3. do
  4. echo $i
  5. echo ok
  6. done

while

  1. while read -p "大哥来点啥?" a
  2. do
  3. "这个卖没了"
  4. done
  5. break 结束循环 脚本继续执行
  6. continue 跳出本次循环

select挑选

  1. echo '大哥来点啥?'
  2. select a in "西瓜" "苹果" "橘子" "结账"
  3. do
  4. case $a in
  5. "西瓜")
  6. echo "大哥西瓜200块一斤"
  7. ;;
  8. "苹果")
  9. echo "苹果便宜点 500一斤"
  10. ;;
  11. esac
  12. done