1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-07 09:08:01 +00:00

Add Partial String Matching In Bash Scripts as a unix til

This commit is contained in:
jbranchaud
2016-04-18 21:14:30 -05:00
parent 1d7e814583
commit a1568d6dfd
2 changed files with 25 additions and 1 deletions

View File

@@ -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)