Why does this command line work:
$ output='Irrelevant'; if [[ $output =~ Something ]]; then echo "I found something in the output." ; fi
And this one give me a strange parse error?
$ output='Irrelevant'; if [[ $output =~ Something ]]; then echo "I found something in the output!" ; fi
-bash: !": event not found
The only change from the first version is that the sentence to be echoed inside quotes ends with an exclamation mark. Why does Bash give me that error in the second version?
In case it matters, this is the output from bash --version:
GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu)
You can wrap the string in single quotes instead of double quotes.
The exclamation point invokes the very useful history expansion function described in the
bashmanual.For instance, to execute the last command that started with the word
mysqltype this:or to execute the last command containing the word
grep, type this:The
bashmanual also documents the syntax of the history expansion operators.