Operating System - HP-UX
1748140 Members
3910 Online
108758 Solutions
New Discussion юеВ

test statement in shell script

 
SOLVED
Go to solution
Maureen Gunkel
Trusted Contributor

test statement in shell script

I am modifying an existing script, and I have a statement like this:
if [[ -a filename ]] then ....
I have searched and studied and cannot figure out exactly what it means. The documentation tells me that -a is an 'and' operator, but what is it comparing to? Please help, I like to understand what I'm running!
No matter where you go, there you are.
3 REPLIES 3
Kofi ARTHIABAH
Honored Contributor
Solution

Re: test statement in shell script

Maureen:

That (-a) is the korn shell argument for testing if file exists. It does not exist under bourne shell or c shell.

man ksh

nothing wrong with me that a few lines of code cannot fix!
f. halili
Trusted Contributor

Re: test statement in shell script

The "-a" that you are using is used to check an object.
Using "-a" to test an object will test if it exist.
Example:

if [[ -a name_of_filename ]]
then
echo "file exists"
fi

The -a is also the "AND" operator as used in most scripts.

`fnhalili`
derekh
Dan Hetzel
Honored Contributor

Re: test statement in shell script

Kofi,

The -a test operator works in posix shell as well

example:
[[ -a filename ]] && echo "file exists"

man posix-sh

Best regards,

Dan
Everybody knows at least one thing worth sharing -- mailto:dan.hetzel@wildcroft.com