How do I replace a string at the end of a variable using a bash shell script?
-
Usage is ${name/%pattern/string}
Check line 3.
declare -A MyBucketList MyBucketList=([1]="The rain in Spain stays mainly on the plain" [2]="To get to Mars you need air" [3]="Climb Mount Everest") echo ${MyBucketList[1]/%plain/farm}
The word
plain
gets replaced withfarm
$ ./associative_array.sh The rain in Spain stays mainly on the farm
We are using arrays but it applies to any variable.
© Lightnetics 2024