Showing results for 
Search instead for 
Do you mean 

Easy one...

SOLVED
Go to Solution
Super Advisor

Easy one...

Hi everyone,

Easy one for ya. How is the best way to have a script verify that something exists (like a directory, etc) before executing a set of commands? Thanks
2 REPLIES
Highlighted
Honored Contributor

Re: Easy one...

Hi Bobby,

If it is a thing like link, file, directory, then you can test it with '-a'. If you want to be more specific like if the thing is a symbolic link (-h), or a directory (-d), use that specific option. 'man ksh'.

#!/usr/bin/ksh

myfunction()
{
your_commands
}

if [ -a /somedirectory ]
then
myfunction
else
echo "/somedirectory is missing"
fi

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Super Advisor

Re: Easy one...

Excellent!!! Thanks Sri!!! Told you it was easy. Just didn't know the easiest way to do it.