Linux read命令

读取n个字符存入变量(不用按回车,输入到第n个自动结束):

[student@myhost ~]$ read -n 3 a
123[student@myhost ~]$ echo $a
123

无回显方式读取密码:

[student@myhost ~]$ read -s  passwd
[student@myhost ~]$ echo $passwd
password

显示提示信息:

[student@myhost ~]$ read -p "Please input:" a
Please input:input
[student@myhost ~]$ echo $a
input

在特定时间内输入(时间结束前需按回车):

[student@myhost ~]$ read -t 2 a
aa
[student@myhost ~]$ echo $a
aa

定界符作为读取结束标志:

[student@myhost ~]$ read -d ";" a
aa;[student@myhost ~]$ echo $a
aa
posted @ 2022-01-15 21:38  epiphanyy  阅读(9)  评论(0)    收藏  举报  来源