Bash traps
zlutystrop
565 views
Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
#!/usr/bin/env bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function cleanup() {
RM=$1
printf "====TRAP====\nDoing some cleanup...\n"
# ...
printf "OK.\n"
exit 0
}
printf "The script runs here...\n"
trap cleanup EXIT
printf "...and also here.\n"
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content