Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save miladvafaeifard/659d2bf8f4207a57527c472a3c2f0d1d to your computer and use it in GitHub Desktop.
Save miladvafaeifard/659d2bf8f4207a57527c472a3c2f0d1d to your computer and use it in GitHub Desktop.
Bash shell documentation
In bash shell scripting, the if statement supports the following options for testing conditions:
-a: Tests if a file exists.
-b: Tests if a file exists and is a block special file.
-c: Tests if a file exists and is a character special file.
-d: Tests if a file exists and is a directory.
-e: Tests if a file exists (same as -a).
-f: Tests if a file exists and is a regular file.
-g: Tests if a file has its setgid bit set.
-h: Tests if a file is a symbolic link (same as -L).
-k: Tests if a file has its sticky bit set.
-L: Tests if a file is a symbolic link.
-n: Tests if the argument is non-empty.
-p: Tests if a file is a named pipe.
-r: Tests if a file is readable.
-s: Tests if a file has a non-zero size.
-t: Tests if file descriptor is open and associated with a terminal device.
-u: Tests if a file has its setuid bit set.
-w: Tests if a file is writable.
-x: Tests if a file is executable.
=: Tests if two strings are equal.
!=: Tests if two strings are not equal.
-eq: Tests if two integers are equal.
-ne: Tests if two integers are not equal.
-gt: Tests if one integer is greater than another.
-ge: Tests if one integer is greater than or equal to another.
-lt: Tests if one integer is less than another.
-le: Tests if one integer is less than or equal to another.
Note that these options are not exhaustive and may vary slightly depending on the version of bash you are using.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment