2

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.

Stefan van den Akker
  • 6,242
  • 7
  • 43
  • 62
Enrichman
  • 10,917
  • 11
  • 68
  • 97

1 Answers1

1

Quote $MESSAGE as well. If that variable does contain a [, it will affect the parsing.

if [ "$MESSAGE" = "username [$USERNAME] is already taken" ]
chepner
  • 446,329
  • 63
  • 468
  • 610