标签: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对应的序号的值
标签:bash 标准输入 ctr 通过命令 命令 exp bre tor select
原文地址:https://www.cnblogs.com/zhudaheng123/p/14593664.html