有时我需要问用户是/否来确认某些内容。
通常我使用这样的东西:
# Yes/no dialog. The first argument is the message that the user will see.
# If the user enters n/N, send exit 1.
check_yes_no(){
while true; do
read -p "$1" yn
if [ "$yn" = "" ]; then
yn='Y'
fi
case "$yn" in
[Yy] )
break;;
[Nn] )
echo "Aborting..."
exit 1;;
* )
echo "Please answer y or n for yes or no.";;
esac
done;
}
有更好的方法吗?该实用程序可能已经在我的/bin
文件夹中了吗?
@muru,我完全是在偷你的想法。我希望我的代表可以交给你。
—
glenn jackman 2014年
@glennjackman我称之为协作。;)
—
muru 2014年
select
,但否则我看不到更简单的方法。