0

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 ?

Itération 122442
  • 2,644
  • 2
  • 27
  • 73

1 Answers1

3

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

echo "${toto%(*}"
KamilCuk
  • 120,984
  • 8
  • 59
  • 111