linux shell命令之REPLY

时间:2021-03-30 13:53:42   收藏:0   阅读:0


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对应的序号的值

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!