#!/bin/bash
# reply.sh
# REPLY是'read'命令结果保存的默认变量.
echo
echo -n "What is your favorite vegetable? "
read
echo "Your favorite vegetable is $REPLY."
# 当且仅当在没有变量提供给"read"命令时,
#+ REPLY才保存最后一个"read"命令读入的值.
echo
echo -n "What is your favorite fruit? "
read fruit
echo "Your favorite fruit is $fruit."
echo "but..."
echo "Value of /$REPLY is still $REPLY."
# $REPLY还是保存着上一个read命令的值,
#+ 因为变量$fruit被传入到了这个新的"read"命令中.
echo
exit 0
Bash脚本示例
本文介绍了一个简单的Bash脚本实例,展示了如何使用read命令从用户获取输入,并通过变量来存储和显示这些输入。此外,还解释了REPLY变量在不同情况下的行为。

被折叠的 条评论
为什么被折叠?



