
Here's a preview from my zine, Bite Size Bash!! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

read the transcript!
our hero: set -x
set -x
prints out every line of a script as it executes, with all the variables
expanded!
#!/bin/bash
set -x
(I usually put set -x
at the top)
or bash -X
$ bash -x script.sh
does the same thing as putting set -x
at the top of script.sh
you can stop before every line
trap read DEBUG
the DEBUG
“signal” is triggered before every line of code
a fancy step debugger trick
put this at the start of your script to confirm every line before it runs:
trap '(read -p "\[$BASH_SOURCE: $LINENO] $BASH_COMMAND")' DEBUG
read -p
prints a message, press enter to continue$BASH_SOURCE
is the script filename$LINENO
is the line number$BASH_COMMAND
is the next command that will run
how to print better error messages
this die function:
die() { echo $1 >&2; exit 1; }
lets you exit the program and print a message if a command fails, like this:
some_command || die "oh no!"
Saturday Morning Comics!
Want another comic like this in your email every Saturday? Sign up here!