I am trying to validate user input, at the moment what i have is as below :-
echo "\n\tPlease, enter package name to import: \c"
read PACKAGE
So far this works perfect , But if the user does not input any thing it stalls
What I need is, If the user does not enter the name of the package, It should exit and echo a message " no valid input"
ranj1
3
a=
if [ -z "$a" ]
then
echo "No input"
else
echo "Input - $a"
fi
This is what i have :-
If i dont enter the package name i get :-
Thanks
vino
5
if [ !z "$PACKAGE" ]
Was that a typo ? If yes, try if [ -z "$PACKAGE" ]
if [[ -z $PACKAGE ]]
then
echo "Package is empty"
fi
Yup that was a Typo !!
But i still get the same error even after trying all the combinations mentioned above
Thanks
its working fine for me.
try
run your script with set -x option and post the output, that might help to figure out the problem
vino
9
It worked fine for me. A wild guess...probably your /bin/sh isnt linked to /bin/bash (?)
Try this. Not sure how much of a difference it could make...
Change the if statement to if [[ "x$PACKAGE" == "x" ]]
Sorry for the mess guys...It was my mistake...It works great now
Thank you all once again...Vino and Gaurav...thank you both so much
Cheers !!!