diff --git a/SC3061.md b/SC3061.md new file mode 100644 index 0000000..9466bbe --- /dev/null +++ b/SC3061.md @@ -0,0 +1,29 @@ +## `read` without a variable is undefined. + +### Problematic code: + +```sh +while read -r; +do + echo "line: ${REPLY}" +done < foolist +``` + +### Correct code: + +Add a variable to read and use it later on: + +```sh +while read -r foo; +do + echo "line: ${foo}" +done < foolist +``` + +### Rationale: + +This behavior is not allowed [in POSIX](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/read.html). + +### Exceptions: + +None. This warning is not emitted in `ksh` or `bash` where read can be used without an argument. \ No newline at end of file