Last active
January 4, 2019 09:12
-
-
Save AaronPhalen/66f3611668dbfdc3a3ae to your computer and use it in GitHub Desktop.
Bash comparison expression cheat sheet.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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