Operating System - HP-UX
1834150 Members
2448 Online
110064 Solutions
New Discussion

Re: UNIX SHELL TEST COMAND OPTIONS

 
SOLVED
Go to solution
David Fosgate_2
Occasional Advisor

UNIX SHELL TEST COMAND OPTIONS

I'm a Unix shell script newbie, I have been using the test command in the following format
[ -option directory/file ], the options I have read about are :
File test:
-r,-w,-x,-f,-d,-s,-t,
String Test:
-z, -n , !, -a, -o and str = str1 compare

The question: I keep finding other options used : -e in particular. Please advise on what options I'm missing and what they check?
The ones I listed above I have found documentation. I usually see others used in script from long gone programmers.

Happy New Year and Thanks

Dave
3 REPLIES 3
Curtis Larson
Trusted Contributor
Solution

Re: UNIX SHELL TEST COMAND OPTIONS

The test command does have it's own man page which will list most of the common options. Along with that shells also may use a built-in test function. To know what options are supported you'll need to reference the man page for the shell your using, posix, ksh, csh, bash, etc. Also, knowing which version of the shell your using is helpful, as newer versions usually support additional features.

-e in the posix shell is used for testing if the file exists.
David Fosgate_2
Occasional Advisor

Re: UNIX SHELL TEST COMAND OPTIONS

Most of the script written by the programmer was posix verion.

Thanks
Dave
Dan Hetzel
Honored Contributor

Re: UNIX SHELL TEST COMAND OPTIONS

Hi David,

Here are the additional test flags for the posix shell:
-L file True if file is a symbolic link.
-e file True if file exists.
file1 -nt file2
True if file1 is newer than file2.
file1 -ot file2
True if file1 is older than file2.
file1 -ef file2
True if file1 has the same device and i-node number as file2.

# man 1 test
should give you a fairly complete list of all non-posix flags.

Best regards,

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