The resolution text says to assign it to a variable, but I still get the warning when doing so via a guarded statement.
I assume it is expecting variable assignment to look something like:
[[ -e "./lockfile" ]]
retval=$?
However, our scripts run with -e set, so the guarded form is needed to avoid script termination.
For bugs with existing features
Here's a snippet or screenshot that shows the problem:
#!/usr/bin/env bash
set -eu -o pipefail
test_function() {
local retval=0
[[ -e "./lockfile" ]] || retval=$?
return "$retval"
}
main() {
test_function || echo "lockfile does not exist"
}
main "$@"
Here's what shellcheck currently says:
In test.sh line 8:
[[ -e "./lockfile" ]] || retval=$?
^-- SC2319 (warning): This $? refers to a condition, not a command. Assign to a variable to avoid it being overwritten.
For more information:
https://www.shellcheck.net/wiki/SC2319 -- This $? refers to a condition, no...
Here's what I wanted or expected to see:
No warning
The resolution text says to assign it to a variable, but I still get the warning when doing so via a guarded statement.
I assume it is expecting variable assignment to look something like:
However, our scripts run with
-eset, so the guarded form is needed to avoid script termination.For bugs with existing features
shellcheck --versionor "online"): 0.11.0, onlineHere's a snippet or screenshot that shows the problem:
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
No warning