Skip to content

Commit 7d0f234

Browse files
Update replace.md
1 parent ed2c031 commit 7d0f234

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

cheatsheets/shell/replace.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ description: Find and replace text in a file, a variable or a string
66

77
## Using shell parameter expansion
88

9-
Using a variable.
10-
11-
Syntax: `${VARNAME/FIND/REPLACE}`.
9+
Syntax: `${VARNAME//FIND/REPLACE}`. The `//` is necessary for global replacement.
1210

1311
```sh
14-
$ x=football
15-
$ echo ${x/foo/bar}
16-
bartball
17-
$ echo ${x/foo/}
18-
tball
12+
$ x=foo_bar_baz_buzz
13+
$ echo ${x//_/-}
14+
foo-bar-baz-buzz
15+
$ echo ${x/_/-}
16+
foo-bar_bazz_buzz
1917
```
2018

2119

0 commit comments

Comments
 (0)