Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
At <https://austingroupbugs.net/view.php?id=1852>, Steffen Nurpmeso (@sdaoden) writes: > twox() { one "$@$@"; } [...] > shells will give different results for the argument-less call to > twox(). (Here on my box bash(1) is the only one which expands > "$@$@" to nothing.) Geoff Clare responds: > The standard clearly requires "$@$@" to generate zero fields if > there are no positional parameters. The quoted text "if the > expansion is embedded within a word which contains one or more > other parts that expand to a quoted null string, ..." does not > apply because there are no other parts that expand to a quoted > null string. (The second $@ is not a candidate for being such a > part because "the expansion of '@' shall generate zero fields".) Simple reproducer: $ set -- # ensure zero PPs $ set -- "$@$@" $ echo $# 1 Expected output: 0 ksh has further inconsistent behaviour: e.g., for zero positional parameters, ''"$@" correctly yields one empty field, ''"$@$@" yields zero, and ''"$@$@$@" and on yield one again, but ''''"$@$@$@" yields zero -- etc. Analysis: In copyto() in macro.c:705, the mp->quoted variable is increased by one for each shell quote encountered in a word. In varsub() in macro.c:1888, this variable is decreased by two if a quoted $@ is encountered with zero positional parameters. For a simple "$@" which has two quotes, this results in a decrease of two and an mp->quoted value of 0 once both quotes have been parsed. Effectively, both quotes have "disappeared", which allows empty removal to take effect: correct behaviour. But if another $@ exists within the same set of quotes, that decrease by two is done again, causing incorrect behaviour. src/cmd/ksh93/sh/macro.c: - Add new 'atspecial' member to Mac_t struct. - varsub(): When applying the quote count reduction for quoted "$@" with zero PPs, remember the current mp->quoted count in mp->atspecial, and do not apply the reduction again unless mp->quoted has changed from mp->atspecial. This fixes the bug.
- Loading branch information