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.

2 Answers 2

3

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

echo ${x//ome/}

(See the manual.)

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

You cannot. You can use shell patterns, though; see the Parameter Expansion section of the bash man page, scrolling down to ${parameter/pattern/string}.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.