user can enter Yes or yes or YES and its captured in variable say var
if [ $var == [Yy][Ee][Ss] ]
then
#do something
elif [ $var == [Nn] [Oo] ]
then
#do something
I think you got what i want to do. I can use "OR" logic in "if" statement like if ["YES"] || [ "yes"] but do not want to use OR , Is there any way it can be done?
hi,
try this.
echo "Enter Yes or No: "
read a
while true
do
case $a in
[Yy]* )
echo "yes is entered"
break;;
[Nn]* )
echo "no is entered"
break;;
* ) echo "Please enter Yes or No ";;
esac
done
You can use typset to force uppercase (or lowercase):
#typeset -u var
#var=yes
#echo $var
YES
1 Like
Here's an idea - you could convert user input to lower case and then compare it with "yes". Ditto with "no".
$
$ x="Yes"
$
$ echo $x | tr [A-Z] [a-z]
yes
$
$
$ x="YeS"
$
$ echo $x | tr [A-Z] [a-z]
yes
$
$
$ x="YES"
$
$ echo $x | tr [A-Z] [a-z]
yes
$
$
tyler_durden