Firstly yes I have posted this on usalug, but wasnt getting a reply.
Ok here is the script:
Code:
#!/bin/bash
function beans ()
{
#check they answered Yes, yes, y, Y, No, no, n, N
while [ $answer != "No" ] && [ $answer != "no" ] && [ $answer != "Yes" ] && [ $answer != "yes" ] && [ $answer != "y" ] && [ $answer != "n" ] && [ $answer != "Y" ] && [ $answer != "N" ]
do
#if not run function "potatoe"
potatoe
done
#If they have assign a action to their answer.
if [ $answer != "No" ] && [ $answer != "no" ] && [ $answer != "n" ] && [ $answer != "N" ]
then
echo "You said yes"
elif [ $answer != "Yes" ] && [ $answer != "yes" ] && [ $answer != "Y" ]&& [ $answer != "y" ]
then
echo "You said no."
fi
}
function potatoe ()
{
#they have not entered a valid answer.
echo "That is not a valid answer"
echo ""
#call function "sausage"
sausage
}
function sausage ()
{
#ask question again.
read -p "Do you like me? Enter Y/N : " answer
#If they asnwer no then...
if [[ $answer != "Y" ]] && [[ $answer != "y" ]] && [[ $answer != "yes" ]] && [[ $answer != "Yes" ]]
then
echo "You said no"
#If they answered yes then...
elif [[ $answer != "N" ]] && [[ $answer != "n" ]] && [[ $answer != "no" ]] && [[ $answer != "No" ]]
then
echo "You said yes"
fi
}
#script starts here
#Ask the user a simple question
read -p "Do you like me? Enter Y/N : " answer
#call the function "beans"
beans
What I want to do is check to see if the user has not entered anything - just pressed enter, because otherwise the script quite after an error:
Code:
[rob@/home/rob 2.6.15-1.2054_FC5]: ./test2
Do you like me? Enter Y/N :
./test2: line 5: [: !=: unary operator expected
./test2: line 9: [: !=: unary operator expected
./test2: line 12: [: !=: unary operator expected
What to do?
Thanks,
Rob.