Using PS4

suggest change

PS4 is displayes when bash is in debugging mode.

#!/usr/bin/env bash

# switch on debugging
set -x

# define a stupid_func
   echo I am line 1 of stupid_func
   echo I am line 2 of stupid_func

# setting the PS4 "DEBUG" prompt
export PS4='\nDEBUG level:$SHLVL subshell-level: $BASH_SUBSHELL \nsource-file:${BASH_SOURCE} line#:${LINENO} function:${FUNCNAME[0]:+${FUNCNAME[0]}(): }\nstatement: '

# a normal statement
echo something

# function call

# a pipeline of commands running in a subshell 
( ls -l | grep 'x' )

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents