Linux shell腳本讀取用戶輸入的參數


新建一個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:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM