shellcheck
shellcheck copied to clipboard
Warn on trap ... exec
For bugs with existing features
- Rule Id (if any, e.g. SC1000):
- My shellcheck version (
shellcheck --versionor "online"): - [x] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- [x] I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
Here's a snippet or screenshot that shows the problem:
#!/bin/sh
trap "echo more work to do"
exec uptime
Note that other particular POSIX family shells from ash to zsh are also effected.
Here's what shellcheck currently says:
(Nothing)
Here's what I wanted or expected to see:
Warning: traps may be skipped when interacting with exec.
In fact, other shebang or separate set safety instructions, like -eufo pipefail are also reset when exec'ing to other shell scripts.
Unknown how environment variables, whether exported or not, interact with exec.
Frankly, exec is hazardous in shell scripts in very many cases.