码迷,mamicode.com
首页 > 系统相关 > 详细

linux shell命令之REPLY

时间:2021-03-30 13:53:42      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:bash   标准输入   ctr   通过命令   命令   exp   bre   tor   select   


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

标签:bash   标准输入   ctr   通过命令   命令   exp   bre   tor   select   

原文地址:https://www.cnblogs.com/zhudaheng123/p/14593664.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!