3 ms·
Another useful capability I use to do cleanup is `trap`. function cleanup { ... } trap cleanup EXIT See more here: http://linux.die.net/Ba
by narsil 13y ago
Another useful capability I use to do cleanup is `trap`.
function cleanup {
...
}
trap cleanup EXIT
See more here: http://linux.die.net/Bash-Beginners-Guide/sect_12_02.html http://linux.die.net/Bash-Beginners-Guide/sect_12_02.html
- eik3_de 13y agoto clean the command prompt line after CTRL-C: trap "{ echo; exit 1; }" INT
- e12e 13y agoI don't know, if you're fearing a ctrl-c in the middle of one of those newfangled moving, colourized progress bars (hello, npm), "reset" might be more appropriate?
- eik3_de 13y agosure, if you do coloring/bold/underline/inverse in the script, reset would be appropriate. but I wouldn't do it by default, because it's quite slow ('time reset' takes 1s here)
- TorKlingberg 13y agoMy reset also takes suspiciously close to one second. Turns out it sleeps for one second at the end, probably to give the terminal time for something.
- shabble 13y ago"tputs reset" has much the same effect (I think; there are some cases I've noticed it not fully restoring things) without the delay.
- pavel_lishin 13y agoIs there a way to determine whether the exit occurred due to the bash script finishing successfully, or due to an error (via set -o errexit)?
- jacquesm 13y agoYou could trap the error.