read命令简介
2009-12-17 21:29
309 查看
read命令
read命令是一个内置命令,用于从终端或文件读取输入,read命令读取一个输入行,直至遇到换行符。行尾的换行符在读入时被转换成一个空字符。如果read命令后未跟变量名,读入的行将被赋给内置变量REPLY。
你也可以使用read命令来中断程序的运行,直至用户输入一个回车。
如果代-r选项,read命令将忽略反斜杠/新行符对,把反斜杠作为行的一部分。
表14-1 read命令
(续表)
#!/bin/bash
#scriptname: nosy
echo -e "are you happy? /c"
read answer
echo "#answer is the right response."
echo -e "what is your full name? /c"
read first middle last
echo "Hello $first"
echo -n "where do you work? "
read
echo Iguess $REPLY keeps you busy!
read -p "enter your job title: "
echo "I thought you might be an $REPLY."
echo -n "who are your best friends? "
read -a friends
echo "Say hi to ${friends[2]}."
The results:
are you happy? never too happy
never too happy is the right response.
what is your full name? tu you wu
Hello tu
where do you work? NUAA
I guess NUAA keeps you busy!
enter your job title: Com
I thought you might be an Com.
who are your best friends? sj cjs lj
Say hi to lj.
read命令是一个内置命令,用于从终端或文件读取输入,read命令读取一个输入行,直至遇到换行符。行尾的换行符在读入时被转换成一个空字符。如果read命令后未跟变量名,读入的行将被赋给内置变量REPLY。
你也可以使用read命令来中断程序的运行,直至用户输入一个回车。
如果代-r选项,read命令将忽略反斜杠/新行符对,把反斜杠作为行的一部分。
表14-1 read命令
格 式 | 含 义 |
read answer | 从标准输入读取一行并赋值给变量answer |
read first last | 从标准输入读取一行,直至遇到第一个空白符或换行符。把用户键入的第一个词存到变量first中,把该行的剩余部分保存到变量last中 |
read | 标准输入读取一行并赋值给内置变量REPLY |
read –a arrayname | 读入一组词,依次赋值给数组arrayname③ |
格 式 | 含 义 |
read -e | 在交互式shell命令行中启用编辑器。例如,如果编辑器是vi,则可以在输入行时使用vi命令③ |
read –p prompt | 打印提示符,等待输入,并将输入赋值给REPLY变量③ |
read –r line | 允许输入包含反斜杠③ |
#scriptname: nosy
echo -e "are you happy? /c"
read answer
echo "#answer is the right response."
echo -e "what is your full name? /c"
read first middle last
echo "Hello $first"
echo -n "where do you work? "
read
echo Iguess $REPLY keeps you busy!
read -p "enter your job title: "
echo "I thought you might be an $REPLY."
echo -n "who are your best friends? "
read -a friends
echo "Say hi to ${friends[2]}."
The results:
are you happy? never too happy
never too happy is the right response.
what is your full name? tu you wu
Hello tu
where do you work? NUAA
I guess NUAA keeps you busy!
enter your job title: Com
I thought you might be an Com.
who are your best friends? sj cjs lj
Say hi to lj.
相关文章推荐
- Linux read命令简介和使用实例
- read命令简介
- linux中的readelf命令简介
- Shell之readelf命令简介
- VC中cl.exe命令参数简介(转载,部分在vs2005进行了验证)
- Linux Shell及常用命令简介
- 关于Dos命令的使用简介
- Redis 命令简介
- HDFS的简介及基本操作(常用的命令参数介绍)
- read命令-输入参数不区分字母大小写
- Linux curl命令简介
- git submodule 使用命令简介
- Vi命令简介
- Git的初次使用 ; Git常用命令查询 ; Git push ; Git pull 2011-12-16 17:32 在介绍安装和简单使用前,先看一下百度百科中的简介吧: ———————————
- od命令 简介
- linux命令之 交互式输入read
- Linux/UNIX命令dd简介
- 关于Linux下的Grep命令简介
- Oracle 零基础学习第一天——简介和基本命令学习
- while read 中使用 ssh 免密执行命令 无法循环的问题