Search code examples
bashcommentspipelinesh

bash: comment a long pipeline


I've found that it's quite powerful to create long pipelines in bash scripts, but the main drawback that I see is that there doesn't seem to be a way to insert comments.

As an example, is there a good way to add comments to this script?

#find all my VNC sessions
ls -t $HOME/.vnc/*.pid                  \
    | xargs -n1                         \
    | sed 's|\.pid$||; s|^.*\.vnc/||g'  \
    | xargs -P50 --replace vncconfig -display {} -get desktop \
    | grep "($USER)"                    \
    | awk '{print $1}'                  \
    | xargs -n1 xdpyinfo -display       \
    | egrep "^name|dimensions|depths"

Solution

  • This works too:

    # comment here
    ls -t $HOME/.vnc/*.pid |
     #comment here
     xargs -n1 |
     #another comment
     ...
    

    based on https://stackoverflow.com/a/5100821/1019205. it comes down to s/|//;s!\!|!.