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?

2 Answers 2

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 ] ' 
Sign up to request clarification or add additional context in comments.

Comments

1

Insert as the first line :

set -v 

then run it without -x

2 Comments

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".
@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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.