我是shell脚本的新手,也是编程的初学者。我这里有一个场景,我想问一下。我在下面粘贴了部分脚本,它是大小写开关的一部分。
echo -n "Delete Source File After Encryption : [Y|N] "
read DSFE
if [ $DSFE = "Y" -o $DSFE = "y" ]; then
Do something;
clear
elif [ $DSFE = "N" -o $DSFE = "n" ]; then
Do something;
clear
我想找出如何对上面的代码片段进行编码,以便如果用户输入不是 Y 或 N,它将循环并提示问题。
对此有何评论?
谢谢。
问候凯文
until [[ $DSFE == [YyNn] ]]; do
read -p "Delete Source File After Encryption? [Y|N] " DSFE
done
case $DSFE in
[Yy]) do_something ;;
[Nn]) do_something_else ;;
*) # this code should not be reached
esac