messaging.sh: line 29: [: missing `]'
messaging.sh: line 29: [: missing ']'
You are using the following:
if [ "alerttype" == "notification"]; then`
However, the above command is missing a space
before ]
, it should be:
if [ "alerttype" == "notification" ]; then
^
The basic rules of conditions
When you start writing and using your own conditions, there are some rules you should know to prevent getting errors that are hard to trace. Here follow three important ones:
Always keep spaces between the brackets and the actual check/comparison. The following won’t work:
if [$foo -ge 3]; then
Bash will complain about a "missing ']'".
Source Conditions in bash scripting (if statements)
You're missing a single space.
#BEFORE
if [ "alerttype" == "notification"]; then
#AFTER
if [ "alerttype" == "notification" ]; then
# ^
Another example:
$ if [ "a" == "a"]; then echo "yes"; else echo "no"; fi
-bash: [: missing `]'
no
$ if [ "a" == "a" ]; then echo "yes"; else echo "no"; fi
yes
Missing the space before the ]
Also another format option is:
$ [ "a" == "a" ] && echo "yes" || echo "no"