Open pschyska opened 1 year ago
Also encountering this. Minimal example:
#!/bin/bash
function sayHi() {
echo hi
}
trap 'sayHi' EXIT
exit 0
$ shellcheck test.sh
In test.sh line 4:
echo hi
^-----^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
For more information:
https://www.shellcheck.net/wiki/SC2317 -- Command appears to be unreachable...
Since most of the work for my script is done in a trap
, this causes false positives for almost half of the lines in the file.
$ shellcheck --version
ShellCheck - shell script analysis tool
version: 0.9.0
license: GNU General Public License, version 3
website: https://www.shellcheck.net
This is reproducible on shellcheck.net.
Also encountering the same issue. Any functions I define that are called from any signal trap
specification (not just EXIT
) are getting many if not all lines within flagged as unreachable. I don't feel like it's the right approach to add in-line waivers on these functions for that check as it will then not check cases that are actually unreachable within those functions.
Can we rename this subject to include 'trap'? As there's several issues with SC2317, the trap call being one of them (as mentioned earlier).
#!/bin/sh
cleanup()
{
trap - EXIT
}
trap cleanup EXIT
exit 0
yields
$ shellcheck myscript
trap - EXIT
^-- [SC2317](https://www.shellcheck.net/wiki/SC2317) (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
echo "Need to clean this up"
^-- [SC2317](https://www.shellcheck.net/wiki/SC2317) (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
$
dup of #2542?
For bugs
shellcheck --version
or 'online'): onlineFor new checks and feature suggestions
Here's a snippet or screenshot that shows the problem:
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
This looks like a false positive, because running that script gives the expected outcome:
I don't think that case is covered in the other bug reports.
The following, in this case equivalent, script doesn't trigger the warning: