Created
September 4, 2014 01:45
-
-
Save bruab/ffd6e63e0000a6102c03 to your computer and use it in GitHub Desktop.
Quick demo of a Bash if statement that depends on how many filenames in the working directory match a string
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
#!/bin/bash | |
# we want to know how many files in this directory contain the string 'bar' | |
number_of_matches=`ls | grep -c bar` | |
# uncomment the following line to see how many matches you got: | |
#echo $number_of_matches | |
# if only one match, let me know | |
if [[ $number_of_matches -eq 1 ]] | |
then | |
echo "it's one" | |
else | |
echo "it's not one" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment