linux shell命令之REPLY


vi readreply.sh
#!/bin/bash
#第一部分

echo -n "What is your name?"
read
echo "Your name is $REPLY" #已将变量的值从标准输入读到REPLY

#第二部分
echo -n "What is the name of your father?"
read fname
echo "Your father‘s name is $fname"

echo "But \$REPLY is $REPLY"
执行 ./readreply.sh
What is your name?Jack
Your name is Jack
What is the name of your father?Tom
Your father‘s name is Tom
But $REPLY is Jack


vi selectreply.sh

#!/bin/bash

echo "Pls. choose your profession?"
select var in "Worker" "Doctor" "Teacher" "Student" "Other"
do
echo "\$REPLY is $REPLY"
echo "Your profession is $var"
break
done

执行./selectreply.sh
Pls. choose your profession?
1) Worker
2) Doctor
3) Teacher
4) Student
5) Other
#? 1 #默认提示符为#?, 可以通过命令PS3="Pls. Enter:"修改为Pls. Enter:, 修改后要执行export
$REPLY is 1 #默认将选择写到REPLY
Your profession is Worker #var对应REPLY对应的序号的值

linux shell命令之REPLY

上一篇:shell脚本语句语法使用(超详细)


下一篇:Linux命令之free