Debugging Scripts
PS4 Prefix
Shape Trace Lines
PS4 controls the prefix Bash uses for execution traces. Modeling the prefix helps explain set -x output without printing noisy traces.
Program
Play the script to choose a trace prefix and build one modeled trace line.
ps4_prefix.sh
#!/usr/bin/env bash
prefix=
command="echo ready"
trace_line="${prefix}${command}"
echo "$trace_line"
#!/usr/bin/env bash
prefix=
command="echo ready"
trace_line="${prefix}${command}"
echo "$trace_line"
PS4
`PS4` is the prompt prefix Bash prints before traced commands.
set -x
`set -x` emits commands as Bash expands and runs them.
modeled trace
This example prints one trace-shaped line instead of enabling global tracing.