Linux bash test statement
Testing options after if [[ ]] in bash programming:
1. Integer testing
-le less equal
-lt less than
-ge greater equal
-gt greater than
-eq equal
-ne not equal
2. Character testing
==
!=
>
<
-n test if string is not null
-s test if string is null
3. File testing
-e test if file exists
-f test if file is a regular file
-d test if path is a directory
-r test if file is readable by current user
-w test if file is writable by current user
-x test if file is executable by current user
For example, check if a file exists:
if [[ -e /etc/passwd ]]; then
echo "File exist"
else
echo "File not exist"
fi
Back to Table of Contents
Disclaimer
- License under
CC BY-NC 4.0
- Copyright issue feedback
me#imzye.com
, replace # with @ - Not all the commands and scripts are tested in production environment, use at your own risk
- No personal information is collected.
Feedback