-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
For bugs
- Rule Id (if any, e.g. SC1000): SC2031
- My shellcheck version (
shellcheck --versionor "online"): - The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
For new checks and feature suggestions
- https://www.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:
#!/bin/bash
set -Eeuo pipefail
random_fail() {
if [ $((RANDOM % 100)) -lt 50 ]; then
return 1
fi
return 0
}
random_fail | tee /tmp/a
# I don't want this to fail immediately, but I want the exit code
# ... also I have other pipes I want to guard against (instead of "consuming" the $?)
(random_fail && RC=0 || RC=$?) | tee /tmp/a
echo "RC: $RC"
# But that triggers SC2030/SC2031. There's a suggestion about using <(), so ... might work?
tee /tmp/a < <(random_fail && RC=0 || RC=$?)
echo "RC: $RC"
# Fun fact: It won'tHere's what shellcheck currently says:
[Line 17:](javascript:setPosition(17, 17))
(random_fail && RC=0 || RC=$?) | tee /tmp/a
^-- [SC2030](https://www.shellcheck.net/wiki/SC2030) (info): Modification of RC is local (to subshell caused by (..) group).
[Line 18:](javascript:setPosition(18, 11))
echo "RC: $RC"
^-- [SC2031](https://www.shellcheck.net/wiki/SC2031) (info): RC was modified in a subshell. That change might be lost.
Here's what I wanted or expected to see:
+ Also for l22, l23
ggjulio
Metadata
Metadata
Assignees
Labels
No labels