You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My shellcheck version (shellcheck --version or "online"): online
I tried on shellcheck.net and verified that this is still a problem on the latest commit
It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue
Here's a snippet or screenshot that shows the problem:
#!/bin/sh
hu="x$hu"
number=$(( number+1))
Here's what shellcheck currently says:
nothing
The problem is, it does consider that the right part of the = is evaluated first and thus the variable is first used and later assigned to itself. Especially with arithmetic operations, this is highly problematic.
Here's what I wanted or expected to see:
Warning: "Variable hu referenced before assigned."
Warning: "Variable number referenced before assigned."
The text was updated successfully, but these errors were encountered:
You're right, of course. This is something I really want to fix in the general case, but it requires some significant infrastructure improvements that I haven't gotten around to (specifically, building a useful control flow graph of the script).
I spent a few minutes yesterday scratching my head until I realized I had made this error.
It surprised me that Shellcheck didn't catch it for me, as it does amazingly well at detecting my stupid mistakes overall.
@koalaman , when you say you want to fix this "in the general case", do you mean to imply there's a simpler, dumber fix for this that you don't want to use, because analogous problems will exist elsewhere?
For bugs
shellcheck --version
or "online"): onlineHere's a snippet or screenshot that shows the problem:
Here's what shellcheck currently says:
nothing
The problem is, it does consider that the right part of the
=
is evaluated first and thus the variable is first used and later assigned to itself. Especially with arithmetic operations, this is highly problematic.Here's what I wanted or expected to see:
Warning: "Variable hu referenced before assigned."
Warning: "Variable number referenced before assigned."
The text was updated successfully, but these errors were encountered: