shellcheck
shellcheck copied to clipboard
SC2094 triggers for: cat <<< "$(get_new_content f)" > f
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. - [x] The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- [x] 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.
(Loosely related to https://github.com/koalaman/shellcheck/issues/473, perhaps, but it seemed different enough and I did not want to flood on someone else’s ticket.)