Input validation ?

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 :frowning:

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"

have you tried if-else

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

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 :frowning:

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

It worked fine for me. A wild guess...probably your /bin/sh isnt linked to /bin/bash (?) :confused:

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 :slight_smile:

Thank you all once again...Vino and Gaurav...thank you both so much :slight_smile:

Cheers !!!