Linux shell脚本读取用户输入的参数
新建一个test.sh文件
- #!/bin/sh
- echo "1 : For Test"
- echo "2 : For nohup &"
- whiletrue
- do
- echo -n "please enter the number:"
- read line
- echo "$line"
- if[[ $line ="1"]];then
- echo "For Test"
- elif[[ $line ="2"]];then
- echo "For nohup &"
- else
- echo "can not find command"
- fi
- done
运行测试日志如下:
- [root@master batch]# sh test.sh
- 1:ForTest
- 2:For nohup &
- please enter the number:1
- 1
- ForTest
- please enter the number:2
- 2
- For nohup &
- please enter the number:3
- 3
- can not find command
- please enter the number:ss
- ss
- can not find command
- please enter the number:
Linux shell脚本读取用户输入的参数的更多相关文章
- Linux&shell之处理用户输入
写在前面:案例.常用.归类.解释说明.(By Jim) 命令行参数$1为第一个参数,$2为第二个参数,依次类推...示例: #!/bin/bash # using one command line p ...
- Shell 脚本处理用户输入
传递参数 跟踪参数 移动变量 处理选项 将选项标准化 获得用户的输入 bash shell提供了一些不同的方法来从用户处获取数据,包括命令行参数(添加在命令后数据),命令行选项(可以修改命令行为的单个 ...
- shell脚本读取文件+读取命令行参数+读取标准输入+变量赋值+输出到文件
读取url_list文件批量下载网页 url_list http://www.tianyancha.com/company/2412078287 http://www.4399.com/special ...
- Shell脚本中判断输入参数个数的方法投稿:junjie 字体:[增加 减小] 类型:转载
Shell脚本中判断输入参数个数的方法 投稿:junjie 字体:[增加 减小] 类型:转载 这篇文章主要介绍了Shell脚本中判断输入参数个数的方法,使用内置变量$#即可实现判断输入了多少个参数 ...
- 通过Shell脚本读取properties文件中的参数时遇到\r换行符的问题
今天在编写微服务程序启动脚本的时候,遇到一个比较奇葩的问题,下面给出具体描述: 目标:通过读取maven插件打包时生成的pom.properties文件,获取里面的应用名称和应用版本号,然后拼接得到s ...
- Linux - 简明Shell编程13 - 用户输入(UserInput)
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 1 - arguments #!/bin/bash i ...
- Shell 读取用户输入
14.2 读取用户输入 14.2.1 变量 上一章我们谈到如何定义或取消变量,变量可被设置为当前shell的局部变量,或是环境变量.如果您的shell脚本不需要调用其他脚本,其中的变量通常设置为脚 ...
- Linux shell脚本 批量创建多个用户
Linux shell脚本 批量创建多个用户 #!/bin/bash groupadd charlesgroup for username in charles1 charles2 charles3 ...
- Linux Shell脚本面试25问
Q:1 Shell脚本是什么.它是必需的吗? 答:一个Shell脚本是一个文本文件,包含一个或多个命令.作为系统管理员,我们经常需要使用多个命令来完成一项任务,我们可以添加这些所有命令在一个文本文件( ...
随机推荐
- django面试四
Django的优点 功能完善.要素齐全:自带大量常用工具和框架(比如分页,auth,权限管理), 适合快速开发企业级网站. 完善的文档:经过十多年的发展和完善,Django有广泛的实践案例和完善的在线 ...
- kali linux 入侵window实例
我使用Kali Linux的IP地址是192.168.0.112:在同一局域网内有一台运行Windows XP(192.168.0.108)的测试电脑. 本文演示怎么使用Metasploit入侵win ...
- git命令学习
git init:把当前目录变成Git可以管理的仓库git add file:把文件添加到仓库git commit -m "描述语句":把文件提交到仓库git status:该命令 ...
- 【Python】基础练习题-1
#练习1:从键盘输入两个数,并比较其大小,直到输入e/E退出程序 while 1: input_number=raw_inut("please input two numbers,enter ...
- 【Python】创建xml文档
#练习:创建xml文档 import xml.dom.minidom import codecs #在内存中创建一个空的文档 doc = xml.dom.minidom.Document() ...
- 【c++基础】c++提升速度的方法总结
参考 1. C++程序提高运行速度的方法; 2. 提高C++程序运行效率的10个简单方法; 3. C++编程中提高程序运行效率的方式(不断更新); 完
- [LeetCode&Python] Problem 762. Prime Number of Set Bits in Binary Representation
Given two integers L and R, find the count of numbers in the range [L, R](inclusive) having a prime ...
- Fedora瘦身
启用的服务 systemctl list-unit-files --type=service | grep enabled 所有服务 systemctl list-unit-files --type= ...
- C++数组排序
#include<stdio.h> #include<stdlib.h> #include<windows.h> #define SIZE 5 //数组中元素的数量 ...
- 《DSP using MATLAB》Problem 6.23
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...