#!/bin/bash
CHECKUSER=$(grep "$USER" /var/log/string.log)
if [[ $CHECKUSER == "" ]];
then
echo "Please enter y or n? (y/n)?"
read string
if [ "$string" = "y" -o "$string" = "n" ];
then
{
echo "$USER - $string" >> /var/log/string.log
}
else
while [ "$string" != "y" -o "$string" != "n" ];
do
echo "'$string' is an invalid option, please enter y or n: "
read string
done
fi
elif [[ $CHECKUSER == "$USER - n" ]];
then
echo "User selected n"
elif [[ $CHECKUSER == "$USER - y" ]];
then
echo "You've already said that you would like your account backed up."
else echo "User entered something other than y or n"
fi
これはすべてうまくいきます!しかし、y|n 以外を入力すると、無限ループに陥ります。
何か案は?