May 2017
Beginner
552 pages
28h 47m
English
We can either use Bash's inbuilt debugging tools or write our scripts in such a manner that they become easy to debug; here's how:
$ bash -x script.sh
Running the script with the -x flag will print each source line with the current status.
#!/bin/bash
#Filename: debug.sh
for i in {1..6};
do
set -x
echo $i
set +x
done
echo "Script executed"
In the preceding script, the debug information for echo $i will only be printed, as debugging is restricted to that section using -x and +x. The script uses the {start..end} construct to iterate from a start ...