diff --git a/README.md b/README.md index 5e66153..8a3136d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really warrant a full blog post. These are mostly things I learn by pairing with smart people at [Hashrocket](http://hashrocket.com/). -_395 TILs and counting..._ +_396 TILs and counting..._ --- @@ -362,6 +362,7 @@ _395 TILs and counting..._ - [Last Argument Of The Last Command](unix/last-argument-of-the-last-command.md) - [List All Users](unix/list-all-users.md) - [Only Show The Matches](unix/only-show-the-matches.md) +- [Partial String Matching In Bash Scripts](unix/partial-string-matching-in-bash-scripts.md) - [Repeat Yourself](unix/repeat-yourself.md) - [Saying Yes](unix/saying-yes.md) - [Search History](unix/search-history.md) diff --git a/unix/partial-string-matching-in-bash-scripts.md b/unix/partial-string-matching-in-bash-scripts.md new file mode 100644 index 0000000..0421140 --- /dev/null +++ b/unix/partial-string-matching-in-bash-scripts.md @@ -0,0 +1,23 @@ +# Partial String Matching In Bash Scripts + +To compare two strings in a bash script, you will have a snippet of code +similar to the following: + +```bash +if [[ $(pwd) == "/path/to/current/directory" ]] +then + echo "You are in that directory"; +fi +``` + +You may only want to do a partial string match. For this, you can use the +`*` wildcard symbol. + +```bash +if [[ $(pwd) == *"directory"* ]] +then + echo "You are in that directory"; +fi +``` + +[source](http://stackoverflow.com/questions/229551/string-contains-in-bash)