SC3061 – ShellCheck Wiki

See this page on GitHub

Sitemap


In POSIX sh, read without a variable is undefined.

Problematic code:

while read -r;
do
    echo "line: ${REPLY}"
done < foolist

Correct code:

Add a variable to read and use it later on:

while read -r foo;
do
    echo "line: ${foo}"
done < foolist

Rationale:

This behavior is not allowed in POSIX.

Exceptions:

None. This warning is not emitted in ksh or bash where read can be used without an argument.


ShellCheck is a static analysis tool for shell scripts. This page is part of its documentation.