0
0
Bash Scriptingscripting~10 mins

Debugging with PS4 in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A"+ $BASH_SOURCE:$LINENO:"
B"- $BASH_SOURCE:$LINENO:"
C"$BASH_SOURCE-$LINENO>"
D"$LINENO:$BASH_SOURCE>"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect variable names in PS4.
Not quoting the PS4 value properly.
2fill in blank
medium

Complete 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'
AFUNCNAME[0]
BFUNCNAME()
CFUNCNAME
DFUNCNAME[1]
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.
3fill in blank
hard

Fix 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'
A"+"
B"-"
C"|"
D"=>"
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' which can be confused with options.
Using symbols that clutter the debug output.
4fill in blank
hard

Fill 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'
ABASH_SOURCE
BFUNCNAME
CLINENO
DBASH_LINENO
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing LINENO with function name.
Using BASH_LINENO which shows line numbers of functions, not names.
5fill in blank
hard

Fill 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'
Adate +"%H:%M:%S"
BBASH_SOURCE
CLINENO
DFUNCNAME
Attempts:
3 left
💡 Hint
Common Mistakes
Using FUNCNAME instead of LINENO for line number.
Not quoting the date command properly.