Operating System - HP-UX
1753681 Members
5955 Online
108799 Solutions
New Discussion юеВ

question about if and elif statements

 
SOLVED
Go to solution
David Johnson_6
Advisor

question about if and elif statements

I having some trouble running a script with several elif statments.
I believe the problem lies in "[]' or in the setting of the read varable.

Script is attached below
elif start on line 176 of 453.

The stript works, I just can't seem to get the right message display when you don't choose a number.
3 REPLIES 3
Sundar_7
Honored Contributor
Solution

Re: question about if and elif statements

David,

With a quick look at the script, I can suggest you a couple of things

1) If you want to test for null input, -z option with test is preferred than comparing the input against ''.

Try

if [[ -z "$SNUM" ]]
then
echo "NADA!!"
else
echo "Something"
fi

2) elif [[ "$SNUM" < 1 ]]

You should use the operator -le than <.

elif [[ "$SNUM" -lt 1 ]]

-- Sundar


Learn What to do ,How to do and more importantly When to do ?
David Johnson_6
Advisor

Re: question about if and elif statements

I run the script. I put in a letter "s" to see what would happen is user put in a letter. Below ins the result:

Please enter START Number (1 - 15) or (E) to Exit: [s ]
s
/usr/contrib/tools/chkimgprnt.sh[24]: [[-z: not found.
/usr/contrib/tools/chkimgprnt.sh[24]: s: The specified number is not valid for t
his command.

ASLO used a number and got:
Please enter START Number (1 - 15) or (E) to Exit: [5 ]
s
/usr/contrib/tools/chkimgprnt.sh[10]: [Aa-Za]: Syntax error
ccchpl(/usr/contrib/tools)#
Sundar_7
Honored Contributor

Re: question about if and elif statements

[[-z: not found.

There should be a space after [[ and -z
Learn What to do ,How to do and more importantly When to do ?