-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
For bugs
- Rule Id: SC2320
- My shellcheck version: 0.9.0
- The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
For new checks and feature suggestions
- https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this
- I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related
Here's a snippet or screenshot that shows the problem:
#!/bin/bash
echo "hola" >> /tmp/prueba
Codigo=$?
echo $Codigo
Here's what shellcheck currently says:
Codigo=$?
^-- [SC2320](https://www.shellcheck.net/wiki/SC2320) (warning): This $? refers to echo/printf, not a previous command. Assign to variable to avoid it being overwritten.
Here's what I wanted or expected to see:
An "echo" redirected to a file is a file write operation. It is necessary to obtain the exit code of that operation, because writing to a file will fail due to lack of permissions, and sometimes it is necessary to verify it.
Wiki says:
If you intentionally refer to echo to get the result of a write, you can ignore this message. Alternatively, write it out as in if echo $$ > "$pidfile"; then status=0; else status=1; fi
But, I think that a report should be as clean as possible, and I think it is easy to detect these cases so as not to show warnings.
Metadata
Metadata
Assignees
Labels
No labels