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
Command substitution in an if condition masking return values #1510
Comments
I stumble with the same problem on my Windows 10 PC/WSL:
sudo apt install shellchecker from the Bionic repository installs an older version (with this error). It looks like the shellchecker parser is expecting a simple command with local variable assignments (and complains that the actual word corresponding to the command is missing), and doesn't understand that an assignment with a command substitution is an expression in itself, returning an exit code. Except, it works online, and on Windows 10 with 6.0.0 (when NOT using a remote session with WSL). |
Just to make it not sounds like it's a WSL specific problem (which it couldn't be), this throws a warning on *nix (not just on WSL) if ! target="$(/usr/bin/readlink "$HOME/.cache")" || [[ -z "$target" ]]; then
:
fi with
|
For new checks and feature suggestions
Here's a snippet or screenshot that shows the problem:
This is a script hiding return value:
It doesn't stop the execution even if
./tmp
doesn't exist. (unexpected)Here's a fixed version:
It stops at the failure of
ls
. (expected)Here's what shellcheck currently says:
Here's what I wanted or expected to see:
To be honest, I don't understand the exact reasons that the former script completes running the whole script.
But I think it's helpful if it could detect such a problem.
The text was updated successfully, but these errors were encountered: