0

I read Bash : extracting part of a string.

How could I achieve this but for all matches inside a string:

x=something
echo ${x ome}
        ^
     what to put here to get "sthing"

Any other suggestions are appreciated.

Community
  • 1
  • 1
sites
  • 21,417
  • 17
  • 87
  • 146

2 Answers2

3

No, the first answer is not right. All matches are to be removed. Therefore, the answer is:

echo ${x//ome/}

(See the manual.)

Tobias
  • 5,038
  • 1
  • 18
  • 39
0

It was too simple:

${x/ome/}

Another question that occurs to me now, is how could I put regular expressions inside the slashes but this is good for now.

sites
  • 21,417
  • 17
  • 87
  • 146
  • You cannot. You can use shell patterns, though; see the Parameter Expansion section of the `bash` man page, scrolling down to `${parameter/pattern/string}`. – chepner Oct 25 '13 at 01:13