From 8b6af1ec479c867a70f4c42922b71eb782e7f282 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Wed, 15 Dec 2021 20:41:55 +0100 Subject: [PATCH] ajout un handler de sigint pour quitter proprement en cas de ctrl-c --- unitests.sh | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/unitests.sh b/unitests.sh index 28153af..50e8147 100644 --- a/unitests.sh +++ b/unitests.sh @@ -42,6 +42,25 @@ cd $(dirname $0) # copy the executable to current directory cp $MINISHELL . +# to delete the files created during the script + function delete_files + { + files_after="$(ls .)" + diff_files="$(comm -3 <(echo "$FILES_BEFORE") <(echo "$files_after"))" + while read -r line_diff + do + rm -rf "$line_diff" + done < <(echo "$diff_files") + } + +# handle sigint signal + function handler_sigint + { + delete_files + exit 0 + } + trap 'handler_sigint' 2 + # default list of files to be use DEFAULT_FILES="$( find $DEFAULT_DIR | tail -n+2 )" @@ -58,17 +77,6 @@ cd $(dirname $0) echo "" } -# to delete the files created during the script - function delete_files - { - files_after="$(ls .)" - diff_files="$(comm -3 <(echo "$FILES_BEFORE") <(echo "$files_after"))" - while read -r line_diff - do - rm -rf "$line_diff" - done < <(echo "$diff_files") - } - # check for arguments, like options or files list # if no file in arguments, default file list is used function parse_arguments