The problem I am having here is that only the 1st option is executed, no matter if I pick yes or no. What am I doing wrong? How can I get this working right without resorting to a case statement?
echo "This is the max size your lvol can be:"
echo $MAXSIZE
echo
echo Do you want to max out the size of your lvol?
print -n "Enter 'y' for Yes or 'n' for No :"
read ANSWER3
if [ $ANSWER3="n" ] || [ $ANSWER3="N" ] || [ $ANSWER3="no" ] || [ $ANSWER3="No" ]
then
exit
else
continue
fi
if [ $ANSWER3="y" ] || [ $ANSWER3="Y" ] || [ $ANSWER3="yes" ] || [ $ANSWER3="Yes" ]
then
echo
echo "vxassist -g $DISKGROUP growto $LVOL $MAXSIZE"
vxassist -g $DISKGROUP growto $LVOL $MAXSIZE
exit
else
exit
fi
See the if statements for two different ways of ORing $ANSWER3. Your error was that you did not put a space either side of "=".
#!/usr/bin/ksh93
echo "Do you want to max out the size of your lvol?"
read ANSWER3?"Enter 'y' for Yes or 'n' for No : "
if [ $ANSWER3 = "n" -o $ANSWER3 = "N" -o $ANSWER3 = "no" -o $ANSWER3 = "No" ]
then
exit
fi
if [ $ANSWER3 = "y" ] || [ $ANSWER3 = "Y" ] || [ $ANSWER3 = "yes" ] || [ $ANSWER3 = "Yes" ]
then
echo
echo "vxassist -g $DISKGROUP growto $LVOL $MAXSIZE"
vxassist -g $DISKGROUP growto $LVOL $MAXSIZE
fi
exit
A better was of doing what you want to do is to use a case statement as in the following example:
case $ANSWER3 in
y|Y|YES|yes|Yes)
break
;;
n|N|no|NO|No)
echo "No entered. Exiting"
exit
;;
*)
echo "Invalid answer. Exiting"
exit
;;
esac
echo "yes entered"
The reason I didn't want to use a case statement, is because I would have to nest it inside of another case statement, and I had issues when testing....
Here is another solution that was brought to my attention:
echo "This is the max size your lvol can be:"
echo $MAXSIZE
echo
echo Do you want to max out the size of your lvol?
print -n "Enter 'y' for Yes or 'n' for No :"
read ANSWER3
if [ "$ANSWER3" = "n" -o "$ANSWER3" = "N" -o "$ANSWER3" = "no" -o "$ANSWER3" = "No" ]
then
exit
else
continue
fi
if [ "$ANSWER3" = "y" -o "$ANSWER3" = "Y" -o "$ANSWER3" = "yes" -o "$ANSWER3" = "Yes" ]
then
echo
echo "vxassist -g $DISKGROUP growto $LVOL $MAXSIZE"
vxassist -g $DISKGROUP growto $LVOL $MAXSIZE
exit
else
exit
fi