Re: Easy one... (84 Views)
Reply
Super Advisor
TheJuiceman
Posts: 459
Registered: ‎02-20-2002
Message 1 of 3 (84 Views)
Accepted Solution

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
Please use plain text.
Honored Contributor
Sridhar Bhaskarla
Posts: 6,350
Registered: ‎08-15-2001
Message 2 of 3 (84 Views)

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
Please use plain text.
Super Advisor
TheJuiceman
Posts: 459
Registered: ‎02-20-2002
Message 3 of 3 (84 Views)

Re: Easy one...

Excellent!!! Thanks Sri!!! Told you it was easy. Just didn't know the easiest way to do it.
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation