-
Notifications
You must be signed in to change notification settings - Fork 1.8k
SC2313
Vidar Holen edited this page Oct 8, 2021
·
1 revision
read -r foo[index]
read -r "foo[index]"
ShellCheck found an array element passed to read, where the []
was not quoted. This means the array index [index]
will be treated as a glob range, and the word may be replaced or trigger failglob
.
In the problematic example, having a directory named food
will cause the command to become read -r food
instead, since food
matches the glob foo[index]
. The result is assigning a value to the wrong variable.
Quote or escape the pattern as shown to ensure it always reads into the array foo
at index index
.
None.
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!