name=Ricardo
echo "Please enter your name: $name \c"
read newname
[ -n "$newname" ] && name=$newname
设置默认值;打印出来;读取一个新值;如果有新值,则使用它代替默认值。在如何在提示符的末尾删除换行符方面,shell和系统之间存在(或曾经存在)一些差异。'\c'符号似乎在MacOS X 10.6.3上使用3。它可以在System V衍生的Unix的大多数变体上运行,使用Bourne或Korn shell。
echo -n "Something interesting happened. "
DEFAULT="y"
read -e -p "Proceed [Y/n/q]:" PROCEED
# adopt the default, if 'enter' given
PROCEED="${PROCEED:-${DEFAULT}}"
# change to lower case to simplify following if
PROCEED="${PROCEED,,}"
# condition for specific letter
if [ "${PROCEED}" == "q" ] ; then
echo "Quitting"
exit
# condition for non specific letter (ie anything other than q/y)
# if you want to have the active 'y' code in the last section
elif [ "${PROCEED}" != "y" ] ; then
echo "Not Proceeding"
else
echo "Proceeding"
# do proceeding code in here
fi