|
发表于 2005-6-23 03:22:40
|
显示全部楼层
Post by netjumby
看LINUX与UNIX Shell编程指南中有一CASE永远不可能运行到,请前辈帮我看看。
此文在264页,红色部分据我分析经过: ${_ANS := $_DEFAULT}后,它的值已经变成了给它的默认值Y或者N,所以它不可能为空,那么if的条件if ["$_ANS" = ""]就不可能成立。请各前辈指点。谢谢了。
continue_promptYN()
#to call: continue_prompt "string to display" default_answer
{
# continue_prompt
_STR=$1
_DEFAULT=$2
#check we have the right params
if [$# -lt 1];then
echo "continut_prompt: I need a string to display"
return 1
fi
while :
do
echo -n "$_STR [Y..N] [$_DEFAULT]:"
read _ANS
# if user hits return set the default and determine the return vallue
: ${_ANS := $_DEFAULT}
if ["$_ANS" = ""];then
case $_ANS in
Y) return 0
;;
N) return 1
;;
esac
fi #user has selected something
case $_ANS in
y|Y|Yes|YES) return 0 ;;
n|N|NO|No) return 1 ;;
*) echo "Answer either Y or N,default is $_DEFAULT" ;;
esac
echo $_ANS
done
}
我想是打印时少打了一个!吧。如果$_ANS是空,根本没有必要do case. 所以可能是打印错误。 |
|