Reputation: 745
When I use the shell string substitution mechanism, only the first occurrence is replaced.
For instance, If I try to replace the substring @folder
with substring mypod
in the string:
hostname | grep @folder && cat /etc/hosts | grep @folder
I get
hostname | grep mypod && cat /etc/hosts | grep @folder
Here is what I tried:
root@mypod:/# export var="hostname | grep @folder && cat /etc/hosts | grep @folder"
root@mypod:/# echo $var
hostname | grep @folder && cat /etc/hosts | grep @folder
root@mypod:/# var2=${var/@folder/mypod}
root@mypod:/# echo $var2
hostname | grep mypod && cat /etc/hosts | grep @folder
What am I missing?
Thanks in advance
Upvotes: 1
Views: 179
Reputation: 22225
From the bash man-page, section Parameter Expansion: the longest match of pattern against its value is replaced. It does not say "all matches are replaced"
Upvotes: 0