Skip to content

Instantly share code, notes, and snippets.

@AaronPhalen
Last active January 4, 2019 09:12
Show Gist options
  • Save AaronPhalen/66f3611668dbfdc3a3ae to your computer and use it in GitHub Desktop.
Save AaronPhalen/66f3611668dbfdc3a3ae to your computer and use it in GitHub Desktop.
Bash comparison expression cheat sheet.
Author: Aaron R. Phalen | Twitter: @aaron_phalen | Email: [email protected]
BASH Compairson Expressions
===========================
Summary:
A brief introduction to comparison expressions import Bourne Again Shell (BASH).
I. Check for the existence of a file [ -e filepath]
Example:
if [ -e /home/aaron/sample.txt ]; then
echo "sample.txt exists."
OUTPUT: sample.txt exists
II. Check for the existence of a file and executable permissions [ -x filepath ]
Example:
if [ -x /home/aaron/sample.txt ]; then
echo "sample.txt exists and is executable."
OUTPUT: sample.txt exists and is executable.
III. Check for the existence of a file that is a socket.
Example:
if [ -S /home/aaron/sample.txt ]; then
echo "sample exists and is a socket."
else
echo "does not exist or is not a socket."
OUTPUT: does not exist or is not a socket.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment