koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.24k stars 1.77k forks source link

SC2319 - changed with Shellcheck 0.10.0 #2937

Open escoand opened 7 months ago

escoand commented 7 months ago

Shellcheck in 0.10.0 complains about an error which is explicit mentioned in the wiki as not relevant. Shellcheck 0.9.0 and also shellcheck.net don't warn. But this is just happening in some cases, see below.

For bugs

For new checks and feature suggestions

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

image

#!/bin/sh

test -z /test
echo $?
foo=$(echo)
export foo

test -z /test
echo $?

Here's what shellcheck currently says:

In test.sh line 4:
echo $?
     ^-- SC2319 (warning): This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.

Here's what I wanted or expected to see:

nothing

Stikus commented 7 months ago

Same problem with VS Code add-on (https://marketplace.visualstudio.com/items/timonwong.shellcheck/changelog) - it uses 0.10.0:
image

For https://www.shellcheck.net/ all good (maybe due to not updated):
image

cbf123 commented 6 months ago

Just ran into an instance of shellcheck 0.10.0 complaining throwing an SC2319 warning about this code:

#!/bin/bash

[ -f /var/run/.network_upgrade_bootstrap ]
upgr_bootstrap=$?

if [ ${upgr_bootstrap} -eq 0 ]; then
    log_it info "Upgrade bootstrap is in execution"
fi

ifaces=$(update_interfaces ${upgr_bootstrap})
update_routes "${ifaces}"

https://www.shellcheck.net/ thinks it's fine. shellcheck-py-0.9.0.6 also thinks it's fine.

Stikus commented 6 months ago

Looks like https://github.com/koalaman/shellcheck/issues/2952 is duplicate of this issue.

@koalaman @brother Can anyone take a look? Problem is still here.

serge2016 commented 4 months ago

Same here! Hope to see the fix... Help, please!

bbrk24 commented 5 days ago

I also ran into this warning where it was unexpected, but in a different way to the original post:

test ! -s "$errors" || {
    exit_code=$?
    cat "$errors" >&2
    return $exit_code
}
serge2016 commented 5 days ago

Still hope for a fix.