Skip to content

SC2311 is incorrectly not triggered with set -o pipefail #3367

@rolfschr

Description

@rolfschr

For bugs with existing features

Here's a snippet or screenshot that shows the problem:

The following code will echo "This is a bug" inside will_fail when invoked in a subshell because BASH implicitly disables set -e their. This is correctly reported in SC2311. However, when set -o pipefail is set, than SC2311 is not triggered although th problem persists. Here is the code and some screenshots:

> cat test.sh
#!/usr/bin/env bash

#shellcheck enable=check-set-e-suppressed
set -ex

# When setting `set -o pipefail`, SC2311 is _not_ triggered!
# set -o pipefail

will_fail() {
  false
  echo "This is a bug! This should never get executed!"
}

# This will invoke the `echo`. Exactly like SC2311 predicted!
version=$(will_fail)
echo "$version" >/dev/null

# This works as expected: The `echo` will never get executed.
will_fail

Without (!) set -o pipefail, shellsheck reports the problem:
Image

With set -o pipefail, shellcheck doesn't complain but the problem (=set -e is implicitly disabled) persists:

Image

I'm no BASH expert, I found this out the hard way. I am not sure whether Shellcheck is "wrong" here but it is unexpected output at least for me.

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