mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
Syntax and Headline Order
@@ -1,6 +1,6 @@
|
||||
#Double quote to prevent globbing and word splitting.
|
||||
# Double quote to prevent globbing and word splitting.
|
||||
|
||||
### Problematic code:
|
||||
## Problematic code:
|
||||
|
||||
```sh
|
||||
echo $1
|
||||
@@ -8,13 +8,13 @@ for i in $*; do :; done # this one and the next one also applies to expanding ar
|
||||
for i in $@; do :; done
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
## Correct code:
|
||||
|
||||
```sh
|
||||
echo "$1"
|
||||
for i in "$@"; do :; done # or, 'for i; do'
|
||||
```
|
||||
### Rationale
|
||||
## Rationale
|
||||
|
||||
The first code looks like "print the first argument". It's actually "Split the first argument by IFS (spaces, tabs and line feeds). Expand each of them as if it was a glob. Join all the resulting strings and filenames with spaces. Print the result."
|
||||
|
||||
|
Reference in New Issue
Block a user