Skip to content

Instantly share code, notes, and snippets.

@sshimko
Created December 28, 2014 17:17
Show Gist options
  • Save sshimko/629af4091e15bc99dda5 to your computer and use it in GitHub Desktop.
Save sshimko/629af4091e15bc99dda5 to your computer and use it in GitHub Desktop.
A BASH debug shell for scripts
#!/bin/bash
HISTSIZE="10000"
set -o history
function debug() {
# Export arrays since BASH doesn't.
declare -a -p |grep -v BASH_ > ${tmpdir}/bash_arrays
history|sed -E 's/^[[:space:]]*[0-9]+[[:space:]]+//' > ${tmpdir}/debug.hist
PS1="DEBUG SHELL> " HISTFILE=$(ls ${tmpdir}/debug.hist) /bin/bash --rcfile ${tmpdir}/bash_arrays -o history|| true
}
trap debug INT
## Write you script
## Press ctrl-c to drop to the debug shell
## Insert "Read" statements to give yourself an opportunity to drop to the shell at specific points
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment