Hey Guys,
I have a shell script that is very simple and does the following.
#!/usr/bin/bash
set -x
echo -n "can you write device drivers?"
read answer
if [ $answer = Y ]
then
echo "wow, you must be very skilled"
else
echo "neither can i, i am just shell script"
fi
you see where the $answer = Y, i need it to match a pattern , because the obvious problem here is that if i entered "yes" the loop would fail..so please let me know if anything can be done about it.
thanks
Arsenalboy
hope this help you.
while [ "true" ]
do
echo -n "can you write device drivers?"
read answer
case $answer in
y|Y)
echo "YES xD"
;;
n|N)
echo "NO :("
;;
e|E)
echo "Bye!!"
break
;;
*) echo "Wrong response"
esac
done
Hey chipcmc,
i tried your script and it essentially does the same thing as the original code. what i should be able to do is, upon entering a combination of "y", "Y", "Yes" , it should say it was successful and any other word should be deemed as a failure.
thanks
Arsenalboy
?� what is the objective? is that response only could be:
Yes
Y
y
are the correct?....
for this you only to need more conditions in you if :
echo -n "can you write device drivers?"
read answer
if [ $answer = 'Y' ] || [ $answer = "Yes" ] || [ $answer = 'y' ]
then
echo "wow, you must be very skilled"
else
echo "neither can i, i am just shell script"
fi
hey chipcmc,
Thank you for the help. the conditions that you gave me really helped!. Appreciate it
thanks
Arsenal Boy
If that can help you a bit more, you can write:
#!/bin/sh
echo -n "can you write device drivers?"
read answer
case $(echo "$answer" | tr [A-Z] [a-z]) in
y|yes|oui|si|'of course'*)
echo "wow, you must be very skilled"
;;
*)
echo "neither can i, i am just shell script"
;;
esac
exit 0
$(echo "$answer" | tr [A-Z] [a-z]) will always return answer in lower case.
$ ./script.sh
can you write device drivers?Of course, I can
wow, you must be very skilled
hey tukuyomi,
this is exactly what i needed. thank you very much. appreciate your help mate.
cheers
Irishboy