Tips & Tricks

Wrap commands with comments

(Based on - Commenting in a Bash script inside a multiline command)

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 clean 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

And the same with redirect to file:

(
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
) > file

Compressed:

# This will send "one" to STDOUT=output 
# and "two" via STDERR to STDOUT and wc
( echo one ; echo "two three" >&2 ) 2>&1 1>/tmp/output | wc

Or expanded:

(
    ( 
        echo one                # Writes to STDOUT
        echo "two Three" >&2    # Writes to STDERR 
    ) 2>&1 1>/tmp/output        # Redirect STDERR to STDOUT and Redirect original STDOUT to file
) | wc                          # Wordcount original STDERR as STDOUT

Should produce:

  1       1      11

and send “one” to /tmp/output