mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2208 (markdown)
22
SC2208.md
Normal file
22
SC2208.md
Normal file
@@ -0,0 +1,22 @@
|
||||
## Use `[[ ]]` or quote arguments to -v to avoid glob expansion.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
[ -v foo[0] ]
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
[ -v 'foo[0]' ]
|
||||
```
|
||||
### Rationale:
|
||||
|
||||
With `[`, arguments will undergo glob expansion. If a file `foo0` exists when the problematic code is run, it will check for the variable `foo0` instead of the array entry `foo[0]`. If there additionally exists a `foo1`, it will simply fail with an error.
|
||||
|
||||
Use `[[ ]]` or quote the argument.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None.
|
Reference in New Issue
Block a user