Created
November 24, 2017 09:09
-
-
Save crazyzlj/77236b3716e2cc97fe33c232dfcf7f4e to your computer and use it in GitHub Desktop.
useful_shell
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
# contains(string, substring) | |
# | |
# Returns 0 if the specified string contains the specified substring, | |
# otherwise returns 1. | |
# https://stackoverflow.com/questions/2829613/how-do-you-tell-if-a-string-contains-another-string-in-unix-shell-scripting | |
contains() { | |
string="$1" | |
substring="$2" | |
if test "${string#*$substring}" != "$string" | |
then | |
return 0 # $substring is in $string | |
else | |
return 1 # $substring is not in $string | |
fi | |
} | |
ANY_CHANGES=$(git commit -m "Any changes?") | |
contains "$ANY_CHANGES" "nothing to commit" && echo "Yes" | |
contains "$ANY_CHANGES" "nothing to commit" || echo "No" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment