Op 04-03-18 om 16:46 schreef Harald van Dijk: > FreeBSD sh also prints a blank line here. [...] > Like above, FreeBSD sh behaves like ksh. I stand corrected. Is there any port of FreeBSD sh to other operating systems? It would be much more convenient for me to include it in my tests if I didn't have to launch a FreeBSD VM and rsync & run the test scripts separately. > Yes, the inconsistency should be fixed. Either it should be treated as > quoted or as unquoted, but not quoted-unless-it-comes-from-a-variable. I > have no strong feelings on which it should be. Neither do I, so I would default to the behaviour that both pre-exists in dash and corresponds with the majority of other shells. >>> Since 7cfd8be0dc83342b4a71f3a8e5b7efab4670e50c had also changed how >>> "$@" got handled and reverting that changed it, I looked into how >>> this works and fixed another bug. It also changes the handling of $* >>> and $@ when IFS is set but empty: dash 0.5.8 didn't handle empty IFS >>> properly at all, even if all parameters were non-empty. dash 0.5.9.1 >>> preserves empty parameters. With this patch, they get removed just >>> like in bash. POSIX allows for either. >> I don't think it does. POSIX implies that empty $@ and $* generates zero >> fields. 2.5.2 Special Parameters: >> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_02 >> >> | @ >> | Expands to the positional parameters, starting from one, initially >> | producing one field for each positional parameter that is set. >> >> Since there are no positional parameters, no fields should initially be >> produced at all. Same for $*. >> >> So I do believe your patch correctly fixes a bug here. > > By empty parameters, I meant parameters that had been set to an empty > string. It's covered by the 'set -- a ""' in my tests. Ah yes, sorry for misreading. You're right that POSIX allows for either removing or not removing empty fields generated by unquoted $@ and $*. Note that the next iteration of POSIX will likely mandate their removal, though. See the descripton of Austin Group bug 888: http://austingroupbugs.net/view.php?id=888 > You're right that > after 'set --', unquoted $@ should not produce any fields. I hadn't even > noticed that dash got that wrong and that my patch had fixed it. :) [...] >> $ src/dash -c 'printf "%s\n" "${$+\}}"' >> \} >> >> Expected output: } (no backslash), as in bash 4, yash, ksh93, pdksh, >> mksh, zsh. In other words: it should be possible to escape a '}' with a >> backslash within the parameter expansion, even if the expansion is >> quoted. >> >> POSIX ref.: 2.6.2 Parameter Expansion >> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 >> >> | Any '}' escaped by a <backslash> or within a quoted string, and >> | characters in embedded arithmetic expansions, command substitutions, >> | and variable expansions, shall not be examined in determining the >> | matching '}'. > > I believe this actually requires dash's behaviour. This says the first } > isn't examined in determining the matching '}', but only that: it just > says the parameter expansion expression is $+\}. It doesn't say the > backslash is removed. I believe the word "escaped" implies that removal. If a '}' is escaped by a backslash, it's implied that the backslash is removed as this escaping is parsed, just as it's implied that quotes are removed from a quoted string. > I agree that it would be much better to print } here though. All other current shells except bosh (schilytools sh) agree, too -- even FreeBSD sh, and I checked it this time. - M. -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html