VMS-to-Unix Phrase Book
<=  Return           

3.4  Testing Files

Problem

As part of a script execution, you want to test the existence of a file, or test for various file attributes.

Solution

Use the shell's 'file test operators' which are somewhat analogous to DCL's F$PARSE() and F$FILE_ATTRIBUTES() lexical functions.

Discussion

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:

See the ksh man page for a complete list.

See Also

1.4 - Symbols and Logicals;
Chapter 10 of Unix for OpenVMS Users ;
Chapter 46 of Unix Power Tools .


<=  Return           

Colophon:
Best Viewed With Any Browser
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

Typographical
Conventions

Created:  31-Jan-2001 BC
Revised:  27-Mar-2001 BC