Created
December 28, 2014 17:17
-
-
Save sshimko/629af4091e15bc99dda5 to your computer and use it in GitHub Desktop.
A BASH debug shell for scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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