Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SCO Unix: How to determine "no answer" to script prompt 1

Status
Not open for further replies.

chipsharp

Programmer
Jan 9, 2001
8
0
0
US
When the user is prompted for a directory in a script
and they just hit enter, how do I determine that
nothing was entered.

I have tried numerous variations of the script below
and cannot make it work. (and i have no hair left).
I never get the "Nothing entered" echo.

echo "Enter new directory: \c"
read newdir
set $newidr
if [ $1 -lt 1 ]
then
echo "Nothing Entered"
else
cd $newdir
if
 
echo "Enter new directory: "
read newdir
if [[ x$newdir = x ]]
then
echo "Nothing Entered"
else
echo Entered $newdir
fi

(for the POSIX shell (sh or ksh)) Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Mike - Thank you - your answer was perfect. I have tried
it and it works. I do wish I had asked B4 I pulled all
my hair out. Some answers are so simple but I would
never have thought of that one.
Thank you again.

Chip
 
Next time you post a SCO Unix question (though this really applied to ANY Unix ), you might want to do it in the SCO Unix Forum.
Tony Lawrence
SCO Unix/Linux Resources tony@pcunix.com
 
Here is another:

if [ -z $newdir ] ; then
echo "Nothing entered"
else
echo "Something entered"
fi

-z says "if zero length".

Bill.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top