diff --git a/README.md b/README.md index 0ffa121..6eb29b3 100644 --- a/README.md +++ b/README.md @@ -1095,6 +1095,18 @@ source ~/.bashrc cd $hotellogs ``` +## Exit traps + +Make your bash scripts more robust by reliably performing cleanup. + +```bash +function finish { + # your cleanup here. e.g. kill any forked processes + jobs -p | xargs kill +} +trap finish EXIT +``` + # 4. Debugging You can easily debug the bash script by passing different options to `bash` command. For example `-n` will not run commands and check for syntax errors only. `-v` echo commands before running them. `-x` echo commands after command-line processing.