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,661
  • 7
  • 48
  • 63
Enrichman
  • 11,157
  • 11
  • 67
  • 101

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
  • 497,756
  • 71
  • 530
  • 681