Skip to Content
Learn Linux Shell Scripting - Fundamentals of Bash 4.4
book

Learn Linux Shell Scripting - Fundamentals of Bash 4.4

by Sebastiaan Tammer
December 2018
Beginner
452 pages
12h 17m
English
Packt Publishing
Content preview from Learn Linux Shell Scripting - Fundamentals of Bash 4.4

Bash debugging

We have one more trick up our sleeve to prove that values are expanded properly: running the Bash script with debug logging. Look at the following execution:

reader@ubuntu:~/scripts/chapter_09$ bash -x test-shorthand-variable.sh + DIRECTORY=/tmp/+ test -d /tmp/+ test_rc=0+ '[' -d /tmp/ ']'+ simple_rc=0+ [[ -d /tmp/ ]]+ extended_rc=0+ echo 'The return codes are: 0, 0, 0.'The return codes are: 0, 0, 0.

If you compare this to the actual script, you will see that the script text test -d ${DIRECTORY} is resolved to test -d /tmp/ at runtime. This is because, instead of running bash test-shorthand-variable.sh, we're running bash -x test-shorthand-variable.sh. In this case, the -x flag tells Bash to print commands and their arguments ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Bash Scripting Fundamentals

Bash Scripting Fundamentals

Sander van Vugt

Publisher Resources

ISBN: 9781788995597Supplemental Content