Skip to content
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

False positive of SC2261 (“multiple redirections compete for $FD”) #2659

Open
2 tasks done
phi-gamma opened this issue Jan 9, 2023 · 0 comments
Open
2 tasks done

Comments

@phi-gamma
Copy link

  • Rule Id: SC2261
  • My shellcheck version (shellcheck --version or "online"):
  • The rule's wiki page does not already cover this
  • I tried on https://www.shellcheck.net/ and verified that this is
    still a problem on the latest commit

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

#!/usr/bin/env bash
set -euo pipefail

exec {out_fd}>/tmp/whatever

output_both () {
    echo foo
    echo bar >&2
    echo baz
    echo xyzzy >&2
}

output_both >&${out_fd} 2>&${out_fd}

Here's what shellcheck currently says:

$ shellcheck rd.sh

In rd.sh line 13:
output_both >&${out_fd} 2>&${out_fd}
            ^-- SC2261 (error): Multiple redirections compete for stderr. Use cat, tee, or pass filenames instead.
                         ^-- SC2261 (error): Multiple redirections compete for stderr. Use cat, tee, or pass filenames instead.

For more information:
  https://www.shellcheck.net/wiki/SC2261 -- Multiple redirections compete for...

Here's what I wanted or expected to see:

Nothing. The rule should not trigger.

The redirections in the example don’t “compete” for stderr or any
other fd for that matter. $out_fd refers to a file and both stdout
and stderr are correctly redirected to that file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant