Skip to content

Commit a1568d6

Browse files
committed
Add Partial String Matching In Bash Scripts as a unix til
1 parent 1d7e814 commit a1568d6

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really
77
warrant a full blog post. These are mostly things I learn by pairing with
88
smart people at [Hashrocket](http://hashrocket.com/).
99

10-
_395 TILs and counting..._
10+
_396 TILs and counting..._
1111

1212
---
1313

@@ -362,6 +362,7 @@ _395 TILs and counting..._
362362
- [Last Argument Of The Last Command](unix/last-argument-of-the-last-command.md)
363363
- [List All Users](unix/list-all-users.md)
364364
- [Only Show The Matches](unix/only-show-the-matches.md)
365+
- [Partial String Matching In Bash Scripts](unix/partial-string-matching-in-bash-scripts.md)
365366
- [Repeat Yourself](unix/repeat-yourself.md)
366367
- [Saying Yes](unix/saying-yes.md)
367368
- [Search History](unix/search-history.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Partial String Matching In Bash Scripts
2+
3+
To compare two strings in a bash script, you will have a snippet of code
4+
similar to the following:
5+
6+
```bash
7+
if [[ $(pwd) == "/path/to/current/directory" ]]
8+
then
9+
echo "You are in that directory";
10+
fi
11+
```
12+
13+
You may only want to do a partial string match. For this, you can use the
14+
`*` wildcard symbol.
15+
16+
```bash
17+
if [[ $(pwd) == *"directory"* ]]
18+
then
19+
echo "You are in that directory";
20+
fi
21+
```
22+
23+
[source](http://stackoverflow.com/questions/229551/string-contains-in-bash)

0 commit comments

Comments
 (0)