Comments are invalid in multi line bash commands

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the bash category.

Last Updated: 2024-11-21

Why did the following code fail with the error "-F is not a command"

curl https://api.rollbar.com/api/1/deploy/ \
# This corresponds to the post_server_item available
# in the project (not account) settings
-F access_token='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
-F environment=production \
-F revision=$CIRCLE_SHA1 \
-F local_username=$CIRCLE_USERNAME \
-F comment='Deployment via CirclCI'

False Start 1: Was the slash in the right direction?

Yes it was. It should be - and was - a backslash. Here is how to remember what way it goes: - the slash for spreading an command over multiple lines goes in the same direction as folders - it is the opposite direction to the slash in URLs (thus why we do not need to escape URLs on the command line)

The real issue

The issue is that the comments confuse it (whitespace characters after an escape but before the next line) The solution is to move the comments to the top instead.

# This corresponds to the post_server_item available
# in the project (not account) settings
curl https://api.rollbar.com/api/1/deploy/ \
-F access_token='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
-F environment=production \
-F revision=$CIRCLE_SHA1 \
-F local_username=$CIRCLE_USERNAME \
-F comment='Deployment via CircleCI'