confirm() {
local YES="Y"
local NO="N"
local CONT="C"
while :
do
echo –n "(Y)es/(N)o/(C)ontinue? {Y] "
read answer
answer=`echo "$answer" | tr '[a-z]' '[A-Z]'`
echo "$answer"
if [ "$answer"=$YES ]
then
echo "YES"
return 0
elif ["$answer"="$CONT" ]
then
echo "skip skip skip"
return 2
elif [ "$answer"="$NO" ]
then
echo "NO"
return 1
fi
done
}
YES
无论输入是什么,输出总是回显并返回 0。
答案1
您在操作符周围缺少强制性的空格,即=
在您的情况下:
if [ "$answer" = "$YES" ]
这和每一种情况有关。