Linux shell脚本读取用户输入的参数

来源:互联网 发布:数据库服务器cpu 要求 编辑:程序博客网 时间:2024/05/22 04:51

新建一个test.sh文件

  1. #!/bin/sh
  2. echo "1 : For Test"
  3. echo "2 : For nohup &"
  4.  
  5. while true
  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 : For Test
  3. 2 : For nohup &
  4. please enter the number:1
  5. 1
  6. For Test
  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:
阅读全文
0 0