问题
I'm trying to do a simple if
statement but one of the string contains square brackets.
I've tried with \ ' " +
and everything came in my mind.
I've basically this:
if [ $MESSAGE = "username [$USERNAME] is already taken" ]
and in this case I would like to throw an error message.
回答1:
Quote $MESSAGE as well. If that variable does contain a [, it will affect the parsing.
if [ "$MESSAGE" = "username [$USERNAME] is already taken" ]
来源:https://stackoverflow.com/questions/11419668/escaping-square-bracket-in-bash-inside-a-string-for-an-if