#!/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
This all works fine! But if you enter something other than y|n you get stuck in an infinite loop.
Any ideas?
set -xvadded to the script to turn on debug tracing is often very helpful for figuring out what you did wrong.doandthenon the next line as you do (and as I do, give or take the indentation), then you don't need the semicolon at the end of the previous line. The semicolons are necessary when thedoandthenis on the same line as the test.