shell脚本 “read” 用法总结

Read命令
1 定义
Read作用从键盘读入数据,赋给变量

【例】 对read的实验  #以空格为赋值分隔符
 [root@hpc test]# read a b c
1 32 3   
[root@hpc test]# echo $a $b $c
1 32 3
[root@hpc test]# echo $a
1

【例】在shell中使用read命令:
[root@hpc test]# cat read.sh
#!/bin/bash    #写入如下
echo "input first second third :"
read  first second third
echo "the first parameter is $first"
echo "the second parameter is  $second"
echo "the third parameter is $third"

测试:
[root@hpc test]# ./read.sh
input first second third :
aa 11 33
the first parameter is aa
the second parameter is  11
the third parameter is 33
2参数用法
2.1  read answer    从标准输入读取一行并赋值给变量answer
2.2  read first last          从标准输入读取一行,直至遇到第一个空白符或换行符。把用户键入的第一个词存到变量first中,把该行的剩余部分保存到变量last中
2.3  read �Ca arrayname             读入一组词,依次赋值给数组arrayname③
2.4  read �Ce          在交互式shell命令行中启用编辑器。
2.5  read �Cp prompt        打印提示符,等待输入,并将输入赋值给REPLY变量③
2.6  read �Cr line              允许输入包含反斜杠③

 

转自:http://xuegodlinux.blog.51cto.com/10844319/1709989

你可能感兴趣的:(read)