9

What are / is the significance of + and ++ at the beginning of bash debug (set -x) output?

The original text looks like this

++ delete + exitstatus=0 + '[' 0 = 0 ']' ++ delete + whiptail --title 'Command output 1311' --separate-output --scrolltext --msgbox '/usr/bin/raspi-config-DEBUG.sh: line 1311: delete: command not found' 17 80 10 + echo '1317 done printing choice to stdout' 

    1 Answer 1

    17

    The + is the PS4 prompt (just like PS1 usually holds $ or some variation thereof, which is the default interactive prompt). It is outputted before each command executed when tracing is enabled with set -x.

    The bash manual says this:

    PS4

    The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is +.

    The multiple + that you may see are due to commands being executed in subshells.

    Example showing three levels of subshells:

    $ cat script.sh #!/bin/bash echo "$( echo "$( echo hi )" )" 
    $ bash -x script.sh +++ echo hi ++ echo hi + echo hi hi 
    2
    • Great, now for the formatting part - how was it reformatted to look as original text, for future references.
      – user238756
      CommentedSep 13, 2018 at 15:35
    • 1
      @JanHus You can't reformat it to get the original shell script back. In my example, there is no information that tells me exactly what the original commands looked like.
      – Kusalananda
      CommentedSep 13, 2018 at 15:39

    You must log in to answer this question.