Skip to content

Files

Latest commit

 

History

History
31 lines (18 loc) · 939 Bytes

SC2064.md

File metadata and controls

31 lines (18 loc) · 939 Bytes

Pattern: Possible double quote misuse in shell script

Issue: -

Description

With double quotes, all parameter and command expansions will expand when the trap is defined rather than when it's executed.

In the example, 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.

Example of incorrect code:

trap "echo \"Finished on $(date)\"" EXIT

Example of correct code:

trap 'echo "Finished on $(date)"' EXIT

Exceptions

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.

Further Reading