lweegp
October 2, 2006, 10:14pm
1
Hi Gurus,
This is my script:
echo ""
echo "Do you want to execute DWH Test Program?"
echo ""
echo -n "Okay?("y" or "n")=> "
set ret = $<
if ($ret != "y") then
echo ""
echo ""
echo "End."
exit 0
How can I make this script accept uppercase as well? Cos if I type a "Y" it will not recognise and end the program.
Thanks.
wee
Andrek
October 3, 2006, 12:20am
2
You could convert the input string to...
all upper case and test for uppercase Y only
all lower case and test for lowercase y on;y
use the "or" in your if statememt "$ret" != "y" || "$ret" != "Y"
lweegp
October 3, 2006, 12:30am
3
Hi Andrek,
Many thanks for your contribution.
what do u mean by the following sentence:
"You could convert the input string to...
all upper case and test for uppercase Y only
all lower case and test for lowercase y only" ?
i have tried using or in my if statement but they are not giving me the expected result...actually the whole script looks like this:
echo "Do you want to execute DWH Test Program?"
echo ""
echo -n "Okay?("y" or "n")=> "
set ret = $<
if ("$ret" != "y" || "$ret" != "Y") then
echo ""
echo ""
echo "End."
exit 0
endif
echo ""
echo "---- DWH Program is running --------"
echo ""
/bin/rsh -n -l smtadm 140.32.12.34 /spsummit/apl/summit/nss_tools/scripts/test.csh >& /dev/null
Once the prog check if its Yes or No then it will either exit or execute another script.
any advise? thanks again.
wee
change that to
if ("$ret" != "y" && "$ret" != "Y") then
&& is required to be used with !=, ("$ret" != "y" || "$ret" != "Y") will always result in true.
lweegp
October 3, 2006, 1:41am
5
vish_indian:
change that to
if ("$ret" != "y" && "$ret" != "Y") then
&& is required to be used with !=, ("$ret" != "y" || "$ret" != "Y") will always result in true.
wonderful!! thanks so much vish!
Andrek
October 4, 2006, 2:43am
6
Hi my comments
"all upper case and test for uppercase Y only, or
all lower case and test for lowercase y only"
ret=`echo $ret | tr "[:lower:]" "[:upper:]"`
if [ "$ret" != "Y" ]....
or
ret=`echo $ret | tr "[:upper:]" "[:lower:]"`
if [ "$ret" != "y" ]....
or
"Revsisied - Thanks Vish"
if ("$ret" != "y" && "$ret" != "Y")...
Cheers
Hi Check this: Hope It will owrk out
echo "Do you want to execute DWH Test Program?"
echo ""
echo -n "Okay?("y" or "n")=> "
set ret = $<
if [ ! $ret = Y -o ! $ret = y ]
then
echo ""
echo ""
echo "End."
exit 0
endif
echo ""
echo "---- DWH Program is running --------"
echo ""
Please reply me whether its working or nor
prowla
December 8, 2007, 1:39am
8
Alternatives:
Declare your variable as lowercase before using it with:
typeset -l ret
if [ "$ret" = y ] ........
Or check your input with:
case "$ret" in
Y|y) echo "I got a Y";;
*) echo "I did not get a Y";;
esac
Note the use of "$res", which allows ret to be an empty string (ie. user just hit Enter).
You should either declare your input variables as uppercase or lowercase:
typeset -l INPUT1 # everything will be lowercase
typeset -u INPUT2 # everything will be UPPERCASE
Or, you can test for multiple choices at once:
if [[ $INPUT == @(Y|y)* ]]; then
echo Yep
elif [[ $INPUT == @(N|n)* ]]; then
echo Nope
else
echo WhatThe
fi
Note that the astersisk allows you to accept "yes" and "YES" (or "y" + anything).