4

From the description of set in the bash man page:

-v   Print shell input lines as they are read.

Thus, the following example script:

#!/usr/bin/env bash
# setv.sh
set -v
foo=bar
echo $foo

Generates output:

foo=bar
echo $foo
bar

Is there a way for it to prepend some string, say "+ " to each line, so as to clearly indicate which line is a line from the script, and which line is output of a line of from the script. Using the above example, the desired output would be:

+ foo=bar
+ echo $foo
bar
user1404316
  • 3,028
  • 12
  • 23
mbigras
  • 2,928
  • 6
  • 28
  • 45

1 Answers1

4

To get that kind of output you could use $BASH_COMMAND e.g. add

trap 'printf "%s %s\n" + "$BASH_COMMAND" >&2' DEBUG

instead of set -x/v at the top your script.

don_crissti
  • 79,330
  • 30
  • 216
  • 245