You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Simon Brandt edited this page Aug 27, 2025
·
4 revisions
This does not read foo. Remove $/${} for that, or use ${var?} to quiet.
Problematic code:
read$foo
Correct code:
read foo
Rationale:
read takes a variable name, but ShellCheck has noticed that you give it an expanded variable instead. This will populate whatever the variable expands to instead of the variable itself. For example:
foo=bar
read $foo # Reads data into 'bar', not into 'foo'
read foo # Reads data into 'foo'
Exceptions:
If this is intentional and you do want to read a variable through an indirect reference, you can silence this warning with a directive:
# shellcheck disable=SC2229read"$foo"
Or take advantage of the fact that ShellCheck only warns when no parameter expansion modifiers are applied:
read"${foo}"# ShellCheck warnsread"${foo?}"# No warning
${foo?} fails when foo is unset, which is fine since read would have failed too. The main side effect is an improved runtime error message in that case.