One hacky way is just to write your comments as arguments to a no-op command. Particularly useful might be the :
null utility:
set -x
: Some interesting notes on the following are ...
results in:
+ : Some interesting notes on the following are...
The colon command does nothing, accepts whatever arguments you give it, and always succeeds. You get an extra :
at the start of your trace output, but that probably isn't a huge problem for your purpose.
If you don't like the :
an even nastier trick is to use a fake command:
set -x
seq 1 1
Some comment &>/dev/null
true
will output:
+ seq 1 1
1
+ Some comment
+ true
That is, the Some comment
line is printed out as trace output when the shell tries to run it, but the resulting error message is sent to /dev/null
. This is nasty for a lot of obvious reasons, but it also counts as an error for the purposes of set -e
.
Note that in either case, your comment is parsed by the shell in the ordinary way, so in particular if you have any special characters they need to be quoted, and because it's trace output the quoting will be displayed.
___ ()
somehow? to use instead of the:
somehow? this would look nicer:___ some comment
– rubo77 Jul 09 '14 at 12:39___():
to define a function named___
that does nothing. – godlygeek Jul 09 '14 at 13:47