| Summary: | $@ containing quoted string is split into separate arguments | ||
|---|---|---|---|
| Product: | Busybox | Reporter: | Marius <marius> |
| Component: | Standard Compliance | Assignee: | unassigned |
| Status: | RESOLVED INVALID | ||
| Severity: | normal | CC: | busybox-cvs |
| Priority: | P5 | ||
| Version: | 1.31.x | ||
| Target Milestone: | --- | ||
| Hardware: | Other | ||
| OS: | Linux | ||
| Host: | Target: | ||
| Build: | |||
|
Description
Marius
2020-04-16 10:55:02 UTC
Shouldn't the $@ in your script be in double quotes to get the expected result? Yes, it works, but I don't understand. Can you explain? In my view, inside "script.sh 1 2 3", $@ expands into 3 elements: 1 2 3 while "$@" expands inside the quotes creating just one element: "1 2 3" So, after it's expanded, for i in 1 2 3 ; do echo $i ; done outputs: 1 2 3 and for i in "1 2 3" ; do echo $i ; done outputs: 1 2 3 As described in the POSIX document you referenced $@ is a special case when it's within double quotes (in certain defined circumstances). Unlike other quoted expansions it normally *doesn't* expand to a single string. The bash documentation says of this case: That is, "$@" is equivalent to "$1" "$2" ... My mistake. |