Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to enable debugging output with PS4.
Bash Scripting
export PS4=[1]
set -x
ls
set +x Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names in PS4.
Not quoting the PS4 value properly.
✗ Incorrect
Setting PS4 to "+ $BASH_SOURCE:$LINENO:" shows the script name and line number before each command when debugging is enabled.
2fill in blank
mediumComplete the code to print the current function name in PS4 during debugging.
Bash Scripting
export PS4='+ $BASH_SOURCE:$LINENO:$[1]: ' set -x myfunc() { echo "Hello" } myfunc set +x
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using FUNCNAME without index which prints the whole array.
Using FUNCNAME[0] which is the current function, not the caller.
✗ Incorrect
FUNCNAME[1] gives the name of the current function being executed, useful in PS4 for debugging function calls.
3fill in blank
hardFix the error in the PS4 assignment to correctly show timestamp and line number.
Bash Scripting
export PS4='$(date +"%T") [1] $LINENO: ' set -x ls set +x
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' which can be confused with options.
Using symbols that clutter the debug output.
✗ Incorrect
Using '+' as a separator in PS4 is common and clear; it separates the timestamp and line number nicely.
4fill in blank
hardFill both blanks to create a PS4 that shows script name and function call depth.
Bash Scripting
export PS4='+ $[1]:$[2]> ' set -x func() { echo "Test" } func set +x
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing LINENO with function name.
Using BASH_LINENO which shows line numbers of functions, not names.
✗ Incorrect
BASH_SOURCE shows the script name; FUNCNAME shows the function call stack, useful for debugging depth.
5fill in blank
hardFill all three blanks to create a PS4 that shows timestamp, script name, and line number.
Bash Scripting
export PS4='[[1]] $[2]:[3]: ' set -x ls set +x
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using FUNCNAME instead of LINENO for line number.
Not quoting the date command properly.
✗ Incorrect
This PS4 shows the current time, script name, and line number for detailed debugging info.