1751941 Members
5146 Online
108783 Solutions
New Discussion юеВ

script help

 
SOLVED
Go to solution
Khashru
Valued Contributor

script help

Hi,

I am using the following two lines in one of my script

Enter user name
read NAME

I want to stop entering null value. If someone enters enter without giving character then i want to echo a warning.
5 REPLIES 5
Patrick Wallek
Honored Contributor
Solution

Re: script help

Something like this ought to work.....

if [[ ${NAME} = "" ]] ; then
echo "you must enter something"
fi
Hein van den Heuvel
Honored Contributor

Re: script help


How about:

/mnt/root # cat x
#!/bin/sh
a=""
while [ "${a}" = "" ]
do
echo -n "Please enter name : "
read a
done
echo "---> $a <----"


Please be sure to check some basic shell programming books of web pages.
Pretty much the very question you asked is answerred in one that popped up with google: +unix +sh +while:
http://steve-parker.org/sh/loops.shtml

hth,
Hein.

Muthukumar_5
Honored Contributor

Re: script help

Use as,

echo "Enter User Name"
read NAME

if [[ -z ${NAME} ]]
then
echo "User name is null. Enter it."
fi
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: script help

Enter user name
read NAME

while [ NAME = "" ]
do
echo -n "Its null, Enter a Name: "
read a
done

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Arturo Galbiati
Esteemed Contributor

Re: script help

Hi,
read NAME"?Enter user name "
if [[ -z $NAME ]] ; then
echo "you must enter something"
fi

HTH,
Art