loading
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# To replace first, use ${parameter/pattern/string}

v1="I love Suzi and Marry"
echo "${v1/Suzi/Sara}"

v2="I love Suzi and Marry"
v3="Sara"
echo "${v2/Suzi/$v3}"



# To replace all, use ${parameter//pattern/string}
message='The secret code is 12345'
echo "${message//[0-9]/X}"

v4="Suzy, Suzy, Suzy"
v5="Sara"
echo "${v4//Suzy/Sara}"



v6=$(echo $v2 | sed "s/Suzi/$v3/g")

echo $v6

v7=$(sed "s/Suzi/$v3/g" <<< "$v2")

echo $v7



echo "I love Suzi and Marry" > lovers.txt

v8=$(<lovers.txt)
v9="${v8/Suzi/Sara}"

echo $v9

echo "${v9/Marry/Jesica}" > lovers.txt

echo $(<lovers.txt)