December 2018
Beginner
452 pages
12h 17m
English
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 ...