mirror of
https://github.com/Idnan/bash-guide.git
synced 2018-11-09 02:29:39 +01:00
add exit trap trick (#45)
This commit is contained in:
parent
54681a2b22
commit
1131add106
12
README.md
12
README.md
@ -1095,6 +1095,18 @@ source ~/.bashrc
|
|||||||
cd $hotellogs
|
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
|
# 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.
|
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.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user