read 命令详解
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了read 命令详解相关的知识,希望对你有一定的参考价值。
read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量
语法选项
-p read –p “提示语句”,则屏幕就会输出提示语句,等待输入,并将输入存储在REPLY中
-n read –n 个数
-t read –t 时间
-s read -s 选项能够使read命令中输入的数据不显示在监视器上
例子
- 从标准输入读取输入并赋值给变量
[[email protected] ~]$ read readfile
hello,world!!welcome to shell
[[email protected] ~]$ echo $readfile
hello,world!!welcome to shell
[[email protected] ~]$
- 等待一组输入,每个单词之间使用空格隔开,直到回车结束,并分别将单词依次赋值给这三个读入变量。
[xiess@layzj022301 ~]$ read frist second third
the_one the_two the_three
[xiess@layzj022301 ~]$ echo "$frist" "$second" "$third"
the_one the_two the_three
[xiess@layzj022301 ~]$
- REPLY示例
[xiess@layzj022301 ~]$ read -p "Enter your name: "
Enter your name: admin_xiess
[xiess@layzj022301 ~]$ echo $REPLY
admin_xiess
[xiess@layzj022301 ~]$
- 关闭显示
[[email protected] ~]# cat readfile.sh
#!/bin/bash
read -s -p "Enter your password: " password
echo
echo "your password is $password"
[[email protected] ~]# chmod a+x readfile.sh
[[email protected] ~]# sh readfile.sh
Enter your password:
your password is 123456
以上是关于read 命令详解的主要内容,如果未能解决你的问题,请参考以下文章
linux打开终端如何启动scala,如何在终端下运行Scala代码片段?
read ECONNRESET at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) { errno: -4077(代码片段
使用hive查看orc文件 orcfiledump命令详解 异常处理(Failed to read ORC file)
Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta(代码片段
Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta(代码片段