-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
For bugs
- Rule Id (if any, e.g. SC1000): SC2317, SC2317, SC2317
- My shellcheck version (
shellcheck --versionor 'online'): online - I tried on shellcheck.net and verified that this is still a problem on the latest commit
- It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue
For new checks and feature suggestions
- shellcheck.net (i.e. the latest commit) currently gives no useful warnings about this
- I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related
Here's a snippet or screenshot that shows the problem:
#! /usr/bin/env bash
main() {
say_hello
}
say_hello() {
echo 'hello'
}
# poor man's __main__
return 2>/dev/null ||:
main "$@"
exit $?Here's what shellcheck currently says:
Line 12 SC2317: Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
Line 14 SC2317: Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
Line 15 SC2317: Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
Here's what I wanted or expected to see:
This script is made "Pythonic" as it can be run or sourced. When run, it executes main(). When sourced, it loads all functions for later use but does not run main().
I believe the first SC2317 is the bug:
Line 12:
return 2>/dev/null ||:
^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
That : (true) is in fact reachable when script is run, but not sourced.
The successive SC2317s are also reachable. But only when not sourced.
Metadata
Metadata
Assignees
Labels
No labels