10.3.27 isEmptyDir (evaluates existence of contents of directory)
Syntax
isEmptyDir directory-path-name
Description
This command verifies whether the file specified for argument is empty.
This command outputs 1 in the following cases:
-
Directory is empty.
If either of the following conditions is met, 0 is output:
-
The directory is not empty.
-
Directory does not exist.
Arguments
- directory-path-name
-
This command specifies the path name of the 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 a file exists in the directory test and nothing exists in the directory tmp: isEmptyDir test # "0" is output. isEmptyDir tmp # "1" is output. # If the directory dir1 is empty, delete dir1. result=$(isEmptyDir dir1) if [[ $result -eq 1 ]]; then rmdir dir1 fi