Inline comments for Bash?

前端 未结 8 832
深忆病人
深忆病人 2020-12-07 13:28

I\'d like to be able to comment out a single flag in a one-line command. Bash only seems to have from # till end-of-line comments. I\'m looking at tricks like:<

8条回答
  •  囚心锁ツ
    2020-12-07 14:09

    My preferred is:

    Commenting in a Bash script

    This will have some overhead, but technically it does answer your question

    echo abc `#put your comment here` \
         def `#another chance for a comment` \
         xyz etc
    

    And for pipelines specifically, there is a cleaner solution with no overhead

    echo abc |        # normal comment OK here
         tr a-z A-Z | # another normal comment OK here
         sort |       # the pipelines are automatically continued
         uniq         # final comment
    

    How to put a line comment for a multi-line command

提交回复
热议问题