4 ms·
# shellcheck disable=SC2064 trap "cleanup '$SCR_IMG'" EXIT While shellcheck can have false positives, and SCR_IMG probably doesn't have any characters whic
by Arch-TK 3y ago
# shellcheck disable=SC2064
trap "cleanup '$SCR_IMG'" EXIT
While shellcheck can have false positives, and SCR_IMG probably doesn't have any characters which need escaping, it's not exactly wrong in this case.
The command passed to `trap` is evaluated normally, so variable expansions do take place.
trap 'cleanup "$SCR_IMG"' EXIT
Will behave correctly, and the expansion of SCR_IMG won't be susceptible to issues relating to unquoted shell characters.
Alternatively, if you're using a modern bash (this probably won't work on a mac by default), then this is an option too:
trap "cleanup ${SCR_IMG@Q}" EXIT
- bpfrh 3y agothanks for fixing and explaining that, I thought '' would work and forgot about escaping characters.