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

SC2094 triggers for: cat <<< "$(get_new_content f)" > f #2540

Open
2 tasks done
mminot-yseop opened this issue Jul 20, 2022 · 1 comment
Open
2 tasks done

SC2094 triggers for: cat <<< "$(get_new_content f)" > f #2540

mminot-yseop opened this issue Jul 20, 2022 · 1 comment

Comments

@mminot-yseop
Copy link

As far as I know, this does not use the same pipeline and works perfectly reliably.

For bugs

  • Rule Id (if any, e.g. SC1000): SC2094
  • My shellcheck version (shellcheck --version or "online"): Bundled plugin in IntelliJ IDEA 2022.1.3.
  • 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

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

#! /usr/bin/env bash

get_new_content() {
    sed 's/Initial/Final/g' "${1:?}"
}

echo 'Initial content.' > f
cat f

# SHELLCHECK RULE TRIGGERED HERE:
cat <<< "$(get_new_content f)" > f

cat f

Output:

Initial content.
Final content.

(Also see, if you will, that SO answer I just created regarding that trick: https://stackoverflow.com/a/73054135/9089759)

Here's what shellcheck currently says:

Make sure not to read and write the same file in the same pipeline.

Here's what I wanted or expected to see:

Nothing.

@mminot-yseop
Copy link
Author

(Loosely related to #473, perhaps, but it seemed different enough and I did not want to flood on someone else’s ticket.)

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