For bugs
For new checks and feature suggestions
Here's a snippet or screenshot that shows the problem:
#!/bin/sh
mycommand
# echo "Command exited with $?" # OK, SC2320 detected
printf 'Command exited with %d\n' $? # SC2320 NOT detected
if [ $? -ne 0 ]
then
echo "Failed"
fi
Here's what shellcheck currently says:
Line 5 SC2181: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.
Here's what I wanted or expected to see:
+Line 5 SC2320: This $? refers to echo/printf, not a previous command. Assign to variable to avoid it being overwritten.
Line 5 SC2181: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.
For bugs
shellcheck --versionor 'online'): onlineFor new checks and feature suggestions
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:
+Line 5 SC2320: This $? refers to echo/printf, not a previous command. Assign to variable to avoid it being overwritten. Line 5 SC2181: Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?.