2

When I invoke bash with the -x option, it prints each command before it is executed. However - the commands are printed with a "+ " prefix.

Is there a way to get it to print the commands, but without this prefix? With -x or without it?

einpoklum
  • 118,144
  • 57
  • 340
  • 684

2 Answers2

3

You can customize the prefix when using bash -x by setting the variable PS4. So in your .bashrc, you could have something like this:

export PS4=''

Or, if you want to debug something, let it print the line number like this:

export PS4='[ $LINENO ] '
Lasse Meyer
  • 1,429
  • 18
  • 38
1

Insert as the first line :

set -v

then run it without -x

Oliver Gaida
  • 1,722
  • 7
  • 14
  • 1
    `set -v` doesn't print the same thing as `set -x` -- it prints commands *before* variables etc are expanded. For example, if you have `var="value"` and the command `echo {1..2} "$var"`, with `set -x` it prints `+ echo 1 2 value`, but with `set -v` it prints `echo {1..2} "$var"`. – Gordon Davisson Oct 11 '20 at 00:50
  • 1
    @GordonDavisson `set -v` actuallys print the raw input *lines* as they're read; it does not print the *commands* either before or after they're expanded. Compare `for i in 1 2 3; do echo $i; done` with `set -x` and `set -v`. –  Oct 11 '20 at 05:54