新建一个test.sh文件


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

Linux shell脚本读取用户输入的参数的更多相关文章

  1. Linux&shell之处理用户输入

    写在前面:案例.常用.归类.解释说明.(By Jim) 命令行参数$1为第一个参数,$2为第二个参数,依次类推...示例: #!/bin/bash # using one command line p ...

  2. Shell 脚本处理用户输入

    传递参数 跟踪参数 移动变量 处理选项 将选项标准化 获得用户的输入 bash shell提供了一些不同的方法来从用户处获取数据,包括命令行参数(添加在命令后数据),命令行选项(可以修改命令行为的单个 ...

  3. shell脚本读取文件+读取命令行参数+读取标准输入+变量赋值+输出到文件

    读取url_list文件批量下载网页 url_list http://www.tianyancha.com/company/2412078287 http://www.4399.com/special ...

  4. Shell脚本中判断输入参数个数的方法投稿:junjie 字体:[增加 减小] 类型:转载

    Shell脚本中判断输入参数个数的方法 投稿:junjie 字体:[增加 减小] 类型:转载   这篇文章主要介绍了Shell脚本中判断输入参数个数的方法,使用内置变量$#即可实现判断输入了多少个参数 ...

  5. 通过Shell脚本读取properties文件中的参数时遇到\r换行符的问题

    今天在编写微服务程序启动脚本的时候,遇到一个比较奇葩的问题,下面给出具体描述: 目标:通过读取maven插件打包时生成的pom.properties文件,获取里面的应用名称和应用版本号,然后拼接得到s ...

  6. Linux - 简明Shell编程13 - 用户输入(UserInput)

    脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 1 - arguments #!/bin/bash i ...

  7. Shell 读取用户输入

    14.2  读取用户输入 14.2.1  变量 上一章我们谈到如何定义或取消变量,变量可被设置为当前shell的局部变量,或是环境变量.如果您的shell脚本不需要调用其他脚本,其中的变量通常设置为脚 ...

  8. Linux shell脚本 批量创建多个用户

    Linux shell脚本 批量创建多个用户 #!/bin/bash groupadd charlesgroup for username in charles1 charles2 charles3 ...

  9. Linux Shell脚本面试25问

    Q:1 Shell脚本是什么.它是必需的吗? 答:一个Shell脚本是一个文本文件,包含一个或多个命令.作为系统管理员,我们经常需要使用多个命令来完成一项任务,我们可以添加这些所有命令在一个文本文件( ...

随机推荐

  1. css 实现的网页布局

      css 实现网页布局,上中下三部分,中间为固定宽度且分为左右两部分 <!DOCTYPE html> <html> <head> <meta charset ...

  2. HDU 6140 17多校8 Hybrid Crystals(思维题)

    题目传送: Hybrid Crystals Problem Description > Kyber crystals, also called the living crystal or sim ...

  3. HDU 6095 17多校5 Rikka with Competition(思维简单题)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  4. socket 聊天室实现

    server #include <stdio.h> #include <sys/types.h> /* See NOTES */ #include <sys/socket ...

  5. 生成式模型 VS 判别式模型

    1 定义 1.1 生成式模型 生成式模型(Generative Model)会对x和y的联合分布p(x,y)建模,然后通过贝叶斯公式来求得 p(yi|x),然后选取使得p(yi|x) 最大的 yi,即 ...

  6. advanced ip scanner —— 局域网下 ip 及设备的扫描

    advanced ip scanner 下载地址:Advanced IP Scanner - Download Free Network Scanner. 用于扫描当前局域网下全部设备及其 ip,构建 ...

  7. Django框架之下载以及基本命令

    Django的下载与基本命令 pip3 install Django #下载完成后保存在python解释器下的bin文件目录下 创建一个Django Project #命令行输入: django-ad ...

  8. 创建文件夹c++

    linux #include <sys/types.h> #include <sys/stat.h> string filepath; mkdir(filepath.c_str ...

  9. Ubuntu16.04通过GPT挂载硬盘

    一般而言,服务器上挂载的硬盘都是比较大的,传统的对硬盘进行分区需要在终端敲sudo fdisk进行操作,但是, 当挂载的硬盘的容量大于2T的时候,是无法通过sudo fdisk进行挂载的,这个时候必须 ...

  10. SyntaxError: Non-UTF-8 code starting with '\xe5' in file ***.py on line 105, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for

    用charles抓包时, 对抓到的html,放到pycharm中解析, 结果报错: SyntaxError: Non-UTF-8 code starting with '\xe5' in file * ...