mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
29
SC3061.md
Normal file
29
SC3061.md
Normal file
@@ -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.
|
Reference in New Issue
Block a user