Skip to content

Instantly share code, notes, and snippets.

@bruab
Created September 4, 2014 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruab/ffd6e63e0000a6102c03 to your computer and use it in GitHub Desktop.
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
#!/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