1

I have a long command line, longer than but similar to the example below. I would like to add comments to individual argument in the sense of what is shown here:

ssh -N \
    -R :10000:10.0.0.1:80 \ # test system
    -R :10001:10.0.0.2:80 \ # integration system
    -R :10002:10.0.0.3:80 \ # database foo
    -R :10003:10.0.0.4:80 \ # some other server
    example.com

But this sadly does not work as the \ characters here no longer escape the newlines. Instead it escapes the space in front of the # an thus prevents the # from being parsed as the start of a comment (# may not appear inside of a token if it should be parsed as the start of a comment).

This also doesn't work because here, instead of the \ escaping the #, the # now prevents the \ from being interpreted.

-R :10000:10.0.0.1:80 # test system \

Is there any way to somehow mix comments and command line arguments (maybe on individual lines) of a single, long command? If not, what would you suggest I do to somehow associate the data passed to the command with commends to describe it?

1 Answer 1

3

From this StackOverflow question Bash: How to Put Line Comment for a Multi-line Command? comes this answer:


Essentially by using bash's backtick command substitution one can place these comments anywhere along a long command line even if it is split across lines. I have put the echo command in front of your example so that you can execute the example and see how it works.

echo CommandName InputFiles `#1st comment` \
             --option1 arg1 `#2nd comment` \
             --option2 arg2 `#3rd comment`

Another example where you can put multiple comments at different points on one line.

some_cmd --opt1 `#1st comment` --opt2 `#2nd comment` --opt3 `#3rd comment`
1
  • This is both ugly and beautiful at the same time! And it's more robust than the solution I found in the meantime, which is inserting : foo comment inside backticks. Commented Aug 26, 2014 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .