10.3.28 isFileOrDir (evaluates existence of File Directory)
Syntax
isFileOrDir path-name
Description
This command evaluates whether the file or directory specified for argument exists.
This command outputs 1 in the following cases:
-
File or directory exists.
This command outputs 0.
-
Neither file nor directory exists.
Arguments
- path-name
-
This command specifies the path name of the file or directory to be evaluated.
Output to the standard output
1 or 0.
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
Not less than 1 |
Termination with an error |
Examples
If the file log.txt exists and the file tmp.txt does not exist: isFileOrDir log.txt # "1" is output. isFileOrDir tmp.txt # "0" is output. If the directory test exists and directory prog does not exist: isFileOrDir test # "1" is output. isFileOrDir prog # "0" is output. # If file/directory entry1 does not exist, return 1. result=$(isFileOrDir entry1) if [[ $result -eq 0 ]]; then return 1 fi