Skip to main content
3 of 9
added 12 characters in body
Amit
  • 195
  • 7

The pattern matching used in this script "${line#*'Caused by'} is replacing all string (owing to the wildcard *) from the beginning to the end of Caused by in the inputted line and then it compares it with itself to see whether they are equal or not. In the end all it does it checks whether the inputted like contains Caused by or not and then prints Yes

Now something about parameter expansion in short for the ${parameter/pattern/string} format with some examples:

If the pattern begins with /, all matches of pattern are replaced with string. Normally only the first match is replaced.

> test=test > echo ${test//t/-} > -es- 

If pattern begins with #, it must match at the beginning of the expanded value of parameter.

> test=test > echo ${test/#t/-} > -est 

If pattern begins with %, it must match at the end of the expanded value of parameter.

> test=test > echo ${test/%t/-} > tes- 

In your case you haven't used the substitution string, so the given pattern is just being removed from the given input string.

> test=test > echo ${test#*es} > t 

With the parameter expansion syntax it would look like

> test=test > echo ${test/#*es/-} > -t 

Reference: man bash: ${parameter/pattern/string}

Amit
  • 195
  • 7