Itération 122442
Itération 122442

Reputation: 2972

How to expend a variable with a quote, on the quote?

Given the following string:

toto="function(param"

I want to get the substring function from the string above, in bash.

I tried the following:

echo "${toto%(}"

Which gives:

function(param

However, with this example:

echo "${toto%param}"

I get:

function(

As expected.

The expansion did not take place when expanding the the character "(".

Why is that ? How can I extract only the beginning (before the "(" of this string ?

Upvotes: 0

Views: 32

Answers (1)

KamilCuk
KamilCuk

Reputation: 142005

To cut ( and anything after it you have match exactly that.

echo "${toto%(*}"

Upvotes: 3

Related Questions