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
2
  • What do you mean when you say "The output looks like"? What command did you execute to generate that undesirable output? Commented Mar 15, 2018 at 20:11
  • I think I now understand what you are looking for. I'll try to edit your question to make it clearer. Commented Mar 15, 2018 at 20:21

1 Answer 1

5

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.

1
  • 1
    You would probably want to print that on stderr. The OP might also want set -o functrace Commented Mar 15, 2018 at 21:33

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.