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
Shellcheck incorrectly complains about echo and printf commands #2663
Comments
Just like any warnings in any computer language, they are not errors... If you're sure it works as intended you can place disable comments in the code or in the options for shellcheck... Note:No i have not cloned the repo to check the files... Those about
I'm sure the rest are similar... 🤣 |
Thanks for having taken the time to provide a detailed reply. However, it is not clear to me why The URL of the blktests project is https://github.com/osandov/blktests. The blktests project has adopted a "zero shellcheck warnings" policy. There are 152 occurrences of " || return $?" in the blktests project. Changing all occurrences would require a significant effort. |
It's bad style because it references the previous result and introduces coupling. If we have some code, as in the wiki page, like the following mycommand
echo "Command exited with $?" And we now, in the process of development or refactoring, switch up our structure mycommand
myfailingcommand
echo "Command exited with $?" We get unexpeced behaviour, where as with something more idiomatic like mycommand
A=$?
myfailingcommand
echo "Command exited with $A" We at least somewhat decouple the initial command from the next check. It's kinda bad either way. I initially confused this with SC2312, which may be more enlightening to you |
Do you actually understand what it does, step-by-step? 🤔
Fixing bad code always requires efforts, the magnitude is just related to the amount of bad coding in the first place. People think that writing shorter (cryptic) code makes it faster, which is just not true. outside of direct assembler code... [ ... ] || return xxx if test ....; then
return xxx
fi But as you can see this is WAY more human friendly to read for the human, with less opportunity to create a bug with. |
For SC2312 particularly, I've opened #2775 |
Rule id: SC2320
Version: https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz from 2023-01-11.
Here's a snippet or screenshot that shows the problem:
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
None of the above messages. I think all of the above messages are either not useful or indicate a bug in shellcheck.
The text was updated successfully, but these errors were encountered: