Skip to content

SC2031 missing issues with process substitution (<()) #3084

@stdedos

Description

@stdedos

For bugs

For new checks and feature suggestions

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't

Here'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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions