I am trying to set a shell variable and pass it into a command as part of a Shell script with the following code:
SLS_DEBUG_TEXT="" if [ "$ENABLE_DEBUG_LOGGING" = "true" ]; then SLS_DEBUG_TEXT="SLS_DEBUG=* " fi $SLS_DEBUG_TEXT sls create_domain -v $AWS_PROFILE_FLAG --stage $STAGE // gives error #SLS_DEBUG=* sls create_domain -v $AWS_PROFILE_FLAG --stage $STAGE // works correctly
The error I'm getting is:
./sls-deploy.sh: line 110: SLS_DEBUG_TEXT: command not found
if statement is mostly irrelevant but I want to show that this variable needs to be set conditionally (i.e. I don't always want the debug logging enabled). The last line in the code snippet (which is commented out) is what the command should look like if debug logging is enabled and this works correctly.
I have found a few previous posts on here and Stack Overflow where the issue was due to spaces between the equals sign when setting a variable (example) but I don't think I've fallen into that trap here.
Thanks for your help.