I am trying to follow the advice on How to check if a variable is set in Bash?
So our app is being deployed on AWS ECS cluster using CloudFormation Template, and sometimes we may need to switch on debug mode.
It seems the best way is to introduce an env variable DEBUG_MODE
, that when is set to TRUE, the entrypoint.sh script would launch the java app with debug parameters.
Here is my latest attempt, I initially wanted to use && for single IF, but was getting error so trying to isolate it and split it in two:
if [ -z ${DEBUG_MODE+FALSE} ]
then
echo not debug, not set
else
if [ $DEBUG_MODE = TRUE ]
then
echo debug
else
echo not debug, set to $DEBUG_MODE
fi
fi
Output:
user@hostname:~$ export DEBUG_MODE=
user@hostname:~$ sh test.sh
test.sh: 5: [: =: unexpected operator
not debug, set to
I cant seem to figure this out, how to write it so that:
- If DEBUG_MODE is unset, empty, or anything but TRUE, it executes regular java command.
- Only if DEBUG_MODE is TRUE, it executes java command with debug parameters?
Thanks!