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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if file ! exist 1

Status
Not open for further replies.

simanek

Programmer
Jan 19, 2001
137
US
Hi all,

I'm writing a shell script (ksh) and am trying to figure out how to check if a directory exists. Basically, I'm trying to do the following (but it's not working):

if (! /usr/local){
some code
}else{
some other code
}
fi

any clues? Mike
~~~~
simanek@uiuc.edu
"It's a Swingline!"
~~~~
 
Here you go:

#!/usr/bin/ksh

if [ ! -d /usr/local ]
then
print "Not Found!"
else
print "It's Here!"
fi
# OR....
if [ -d /usr/local ]
then
print "It's Here!"
else
print "Not Found!"
fi

Read the man page on ksh. It has a whole bunch of file test operators. ( '-d <dir>' returns true if <dir> exists AND is a directory)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top