bash script debug saída + e ++

0

O que é / é o significado de + e ++ no início da saída bash debug ( set -x )?

O texto original é assim

++ 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'
    
por Jan Hus 13.09.2018 / 17:09

1 resposta

6

O + é o prompt PS4 (assim como PS1 geralmente contém $ ou alguma variação dele, que é o prompt interativo padrão). Ele é enviado antes de cada comando executado quando o rastreio é ativado com set -x .

O manual bash diz isso:

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 +.

Os múltiplos + que você pode ver são devidos a comandos sendo executados em subshells.

Exemplo mostrando três níveis de subcasas:

$ cat script.sh
#!/bin/bash

echo "$( echo "$( echo hi )" )"
$ bash -x script.sh
+++ echo hi
++ echo hi
+ echo hi
hi
    
por 13.09.2018 / 17:16