add exit trap trick (#45)

This commit is contained in:
Ryan Barth 2017-04-16 01:02:21 -07:00 committed by Adnan Ahmed
parent 54681a2b22
commit 1131add106
1 changed files with 12 additions and 0 deletions

View File

@ -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.