-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2064
wileyhy edited this page Jun 29, 2023
·
5 revisions
trap "echo \"Finished on $(date)\"" EXIT
trap "rm -fr '$testdir1' '$testdir2'" $TRAP_SIGNALS
trap "rm $tmp" $TRAP_SIGNALS
trap "${remove_aar_temp}" SIGKILL SIGTERM SIGQUIT EXIT
trap "$(shopt -p extglob)" RETURN
trap 'echo "Finished on $(date)"' EXIT
With double quotes, all parameter and command expansions will expand when the trap is defined rather than when it's executed.
In the example with the Problematic code, the message will contain the date on which the trap was declared, and not the date on which the script exits.
Using single quotes will prevent expansion at declaration time, and save it for execution time.
If you don't care that the trap code is expanded early because the commands/variables won't change during execution of the script, or because you want to use the current and not the future values, then you can ignore this message.