-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SC2317 false positive warning #2542
Comments
It's the #!/bin/sh
foo() { bar; }
exit 0 # comment this out to do away with the finding I disagree with your assertion that it's very common" to end a script with
That said, I agree this finding is confusing and at a minimum it should point to the |
You'll need to remove it from thousands of scripts.In other words that is not a reasonable solution. |
@dimo414 a trap on EXIT will be invoked even with |
I agree that the finding is wrong, I'm just saying |
As already explained this is clearly not the solution. |
I diagree with your assertion too :) The final
so its simply a best practice to always do it. Having said that, you are correct that technically it is not needed. |
As others have stated, explicit
Also, it is not always the case that 'exit 0' is technically not needed as there can can be a reason to override
So I am heartily agreeing that "removing your |
Aliases confuse it, too. #!/bin/sh
foo() { echo "message"; }
alias bar=foo
true # or some other command
RESULT=$?
if [ "$RESULT" -eq 0 ]; then bar; fi
exit "$RESULT" My actual code is more complex, of course, with conditional aliases for multiple functions. Shellcheck 0.9.0 bombards me with "unreachable" messages for every line of every function. I don't remember this happening when I used 0.7.1 (though it's possible I wasn't using shellcheck on these scripts back then). Also please note that the |
I am experiencing this issue as well. I've found `exit 0` to be
particularly useful during debugging, as is `exit 00`, `exit 101` and `exit
"$LINENO"`. It is valid syntax.
Thanks,
Wiley
…On Sun, Jul 9, 2023, 6:51 PM Forest ***@***.***> wrote:
Aliases confuse it, too.
#!/bin/sh
foo() { echo "message"; }
alias bar=foo
true # or some other command
RESULT=$?
if [ "$RESULT" -eq 0 ]; then bar; fi
exit "$RESULT"
My actual code is more complex, of course, with conditional aliases for
multiple functions. Shellcheck 0.9.0 bombards me with "unreachable"
messages for every line of every function. (I don't remember this happening
when I used 0.7.1.)
Also please note that the exit at the end is not a no-op.
—
Reply to this email directly, view it on GitHub
<#2542 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUF2F22OWRGCYYRS7GDYBPLXPNN23ANCNFSM54OGXFDQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
It can't seem to cope with traps like
|
This new check in 0.9.0 appears to have some issues with various forms of "early return", like trap, exit and return. This is tripping up (at least): cmd/zed/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zfs-functions Its not obvious what its complaining about or what the remedy is, so it seems sensible to disable this check for now. See also: https://www.shellcheck.net/wiki/SC2317 koalaman/shellcheck#2542 koalaman/shellcheck#2613 Signed-off-by: Rob Norris <[email protected]>
This new check in 0.9.0 appears to have some issues with various forms of "early return", like trap, exit and return. This is tripping up (at least): cmd/zed/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zfs-functions Its not obvious what its complaining about or what the remedy is, so it seems sensible to disable this check for now. See also: https://www.shellcheck.net/wiki/SC2317 koalaman/shellcheck#2542 koalaman/shellcheck#2613 Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #15089
This new check in 0.9.0 appears to have some issues with various forms of "early return", like trap, exit and return. This is tripping up (at least): cmd/zed/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zfs-functions Its not obvious what its complaining about or what the remedy is, so it seems sensible to disable this check for now. See also: https://www.shellcheck.net/wiki/SC2317 koalaman/shellcheck#2542 koalaman/shellcheck#2613 Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes openzfs#15089
This new check in 0.9.0 appears to have some issues with various forms of "early return", like trap, exit and return. This is tripping up (at least): cmd/zed/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zfs-functions Its not obvious what its complaining about or what the remedy is, so it seems sensible to disable this check for now. See also: https://www.shellcheck.net/wiki/SC2317 koalaman/shellcheck#2542 koalaman/shellcheck#2613 Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #15089
This new check in 0.9.0 appears to have some issues with various forms of "early return", like trap, exit and return. This is tripping up (at least): cmd/zed/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zfs-functions Its not obvious what its complaining about or what the remedy is, so it seems sensible to disable this check for now. See also: https://www.shellcheck.net/wiki/SC2317 koalaman/shellcheck#2542 koalaman/shellcheck#2613 Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes openzfs#15089
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 should not be a warning, the
exit 0
at the end of a script is very common and thequit
function is indeed reachable due to thetrap
. In this case theexit 0
may never be reached if thefoo
command fails for whatever reason and even if theexit 0
is reached thequit
function which will have any cleanup is still activated due to thetrap
.The text was updated successfully, but these errors were encountered: