trap to cleanup temp file on exit

This commit is contained in:
CaptainArk 2018-04-20 20:15:20 +02:00
parent 7679ea3f61
commit ac8bcc821b
1 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,14 @@
#!/bin/bash
# Function to clean temporary file
ExitCleanup() {
if [[ ! -z ${TempFile} ]]; then
[[ -f ${TempFile} ]] && rm ${TempFile}
fi
}
trap ExitCleanup EXIT
# shellcheck source=config
source "$(dirname $0)/config"
@ -55,5 +64,3 @@ for Projects in ${AddedProjects}; do
echo "Project ${ProjectToRemove} has been removed from rss2email configuration !"
fi
done
[[ -f ${TempFile} ]] && rm ${TempFile}