Linux Shell基础知识8 用户输入
来源:互联网 发布:淘宝要几天退货才算 编辑:程序博客网 时间:2024/05/29 19:16
15、处理用户输入
15.1、命令行参数
脚本参数:脚本名 参数1 参数2 ...
获取参数:$1第一个参数,$2第二个参数,...${10}第10个参数
读取程序名称:$0表示程序路径,`basename $0`获得程序名称
参数个数:$#
所有参数:$*单独一个字符串,$@将所有参数作为同一个字符串中的多个单词
参数移位:shift,所有参数左移一个位置
15.2、选项
使用双破折号,在使用参数的同时使用选项。
15.3、getopt
格式:getopt options optstring parameters
说明:用于重新组织命令行参数
options表示选项
optstring表示选项字符串
parameters表示参数
例如:
getopt ab:cd -a -b test1 -cd test2 test3
-a -b test1 -c -d -- test2 test3
在脚本中使用:set -- `getopt `,将命令行参数变量替换为set命令的命令行中的值。
15.4、getopts
格式:getopts optstring variable。
optstring中列出有效选项字母,如果选项字母需要参数值后面加上一个冒号,如果要进制输出错误消息,那么使选项字符串以冒号开头。variable中存放当前参数。环境变量$OPTARG中包含需要参数值的选项要使用的值。环境变量$OPTIND包含值表示停止处理时在参数列表中的位置。
15.5、获取用户输入
基本读取:read 参数名
带提示信息读取:read -p 提示信息 参数名
不指定参数:如果read中未指定参数名,则数据被放置在环境变量REPLY中。
带计时读取:read -t 5
密码读取:read -s
文件读取:cat 文件名 | while read line
- Linux Shell基础知识8 用户输入
- linux shell读取用户输入
- linux shell 处理用户输入
- Linux Shell 读取用户输入
- linux shell获取用户输入
- SHELL脚本的基础知识4——处理用户输入
- SHELL脚本的基础知识4——处理用户输入
- Shell读取用户输入
- shell 获取用户输入
- shell 读取用户输入
- Shell读取用户输入
- 【shell】处理用户输入
- Linux学习-shell脚本编程基础之处理用户输入
- linux shell脚本读取用户输入的参数
- 【Linux】shell---判断用户输入的是否为文件
- linux shell脚本读取用户输入的参数
- Linux命令行与shell编程笔记-13处理用户输入
- linux shell 学习之第13章 处理用户输入
- 如何使UIScrollView的滚动条indicator一直显示
- 基于物品的协同过滤推荐算法——读“Item-Based Collaborative Filtering Recommendation Algorithms”
- html<marquee>标签
- android:windowSoftInputMode属性使用心得
- 51 单片机UART 串口通信[ 方式1 ]实现
- Linux Shell基础知识8 用户输入
- could not initialize proxy - no Session 异常情况探究
- C语言学习笔记7
- Oracle分区表的使用
- centos6.4上zookeeper3.4.5安装与基础设置
- Android EditText中输入值以星号*显示 (密码的实现)
- 网络七层协议详解
- 快速选择Excel中数据区域
- 常用的数据结构