新建一个test.sh文件


  1. #!/bin/sh
  2. echo "1 : For Test"
  3. echo "2 : For nohup &"
  4.  
  5. whiletrue
  6. do
  7. echo -n "please enter the number:"
  8. read line
  9. echo "$line"
  10. if[[ $line ="1"]];then
  11. echo "For Test"
  12. elif[[ $line ="2"]];then
  13. echo "For nohup &"
  14. else
  15. echo "can not find command"
  16. fi
  17. done

运行测试日志如下:


  1. [root@master batch]# sh test.sh
  2. 1:ForTest
  3. 2:For nohup &
  4. please enter the number:1
  5. 1
  6. ForTest
  7. please enter the number:2
  8. 2
  9. For nohup &
  10. please enter the number:3
  11. 3
  12. can not find command
  13. please enter the number:ss
  14. ss
  15. can not find command
  16. please enter the number: