Linux下shell脚本中的read命令

来源:互联网 发布:word2016破解知乎 编辑:程序博客网 时间:2024/05/16 15:05

read命令作用:

从标准输入中读取一行,并把输入行的每个字段的值指定给shell变量

参数:
-a 后跟一个变量,该变量会被认为是个数组,然后给其赋值,默认是以空格为分割符。
-d 后面跟一个标志符,其实只有其后的第一个字符有用,作为结束的标志,会举例说  明。
-p 后面跟提示信息,即在输入前打印提示信息。
-e 在输入的时候可以时候命令补全功能。
-n 后跟一个数字,定义输入文本的长度,很实用。
-r 屏蔽,如果没有该选项,则作为一个转义字符,有的话 就是个正常的字符了。
-s 安静模式,在输入字符时不再屏幕上显示,例如login时输入密码。
-t 后面跟秒数,定义输入字符的等待时间。

-u 后面跟fd,从文件描述符中读入,该文件描述符可以是exec新开启的。

示例:

$ vi shell_0831.sh#!/bin/bashecho "**************************read command**************************"#read -p and -techo "----1.read -p and -t ----"read -t 20 -p "please enter your name:" nameecho $name#read -s -pecho "----2.read -s and -p----"read -s -p "please enter your pass:" passecho -e "\n"echo "your pass is $pass"#read -decho "----3.read -d----"read -d eecho "end as e"

运行脚本程序:

$ ./shell_0831.sh**************************read command**************************----1.read -p and -t ----please enter your name:jackjack----2.read -s and -p----please enter your pass:your pass is 123----3.read -d----abcdffffeend as e



1 0
原创粉丝点击