Return
|
As part of a script execution, you want to test the existence of a file, or test for various file attributes.
Use the shell's 'file test operators' which are somewhat analogous
to DCL's F$PARSE() and F$FILE_ATTRIBUTES()
lexical functions.
The Korn shell supplies a variety of file test operators which can be used to answer basic questions about a file and it's attributes. Here's an example:
input='myfile.txt';
if [ -e $input ]
then echo "$input file already exists";
else echo "no such file: $input";
fi;
Some of the basic file tests operators include:
-d file -
TRUE, if file exists and is a directory.
-e file -
TRUE, if file exists.
-f file -
TRUE, if file exists and is an ordinary file.
-r file -
TRUE, if file exists and is readable by current process.
-s file -
TRUE, if file exists and has size greater than 0 (zero).
-w file -
TRUE, if file exists and is writable by current process.
See the ksh man page for a complete list.
1.4 - Symbols and Logicals;
Chapter 10 of Unix for OpenVMS Users
;
Chapter 46 of Unix Power Tools
.
  Return
|
|
Colophon: |
|
||||
|
This page maintained by: Bill.Costa@unh.edu of the Enterprise Computing Group in the dept of Computing & Information Sevices at the University of New Hampshire |
|
||||