sites
sites

Reputation: 21795

Delete part of string Bash

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.

Upvotes: 0

Views: 2817

Answers (2)

Tobias
Tobias

Reputation: 5198

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

echo ${x//ome/}

(See the manual.)

Upvotes: 3

sites
sites

Reputation: 21795

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.

Upvotes: 0

Related Questions