Re: < "$@" doesn't expand properly?
Marc Chantreux <[email protected]> Sat, 4 Oct 2025 15:31:59 +0200
| Newsgroups | org.kernel.vger.dash |
|---|---|
| Message-ID | <aOEhz5PAKi-xYg28@prometheus> |
On Sat, Oct 04, 2025 at 12:42:30PM +0100, Harald van Dijk wrote:
> On 04/10/2025 07:55, Marc Chantreux wrote:
> > * it's a matter of consistency to me. why "$@" can't behave as "$@" ?
> The word that follows a redirection operator is one of the special contexts
> where operations that split words into multiple fields are disabled for it.
> Variable assignment is another. This is why
>
> foo='multiple words'
> bar=$foo
> echo $foo > $bar
wow ... another thing I ignored after more than 25 years of shell
scripting.
"case $foo" is another example I discovered recently (on this mailing
list AFAIR). The person who answered me talked about a "scalar context".
> It is this principle that dash follows when it expands "$@" as "$*" in these
> contexts. I agree with you that if users want that, they can just write "$*"
> instead, but I do think that when users do write "$@" anyway, treating it as
> "$*" is the least questionable interpretation.
Well ... I see a lot of people who just recomends to quote (and even brace)
everything (so $foo becomes "${foo}" in their coding style) just because
they fear expansions. I try to explain that expansions are good and word
splitting is useful but you have to be carreful but the more we have
exceptions to a simples rules, the more people will try to avoid errors and
go on quoting, losing the benefits of expansions. They finally
claim that "we should rewrite in python instead because shell behavior
is hard to understand".
However un fully understand than when a behavior is still used,
implementors try to make it consistent. Thank you so much for your explainations.
regards.
--
Marc Chantreux
Pôle CESAR (Calcul et services avancés à la recherche)
Université de Strasbourg
14 rue René Descartes,
BP 80010, 67084 STRASBOURG CEDEX
03.68.85.60.79
signature.asc
(application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQQrhynLytp14smlCwy+er2aYc+1WAUCaOEhyQAKCRC+er2aYc+1 WI0wAPoD+Pcis637hbhnMsShVI4PmFPw/KR8DBfLt5itmGq/AAEAucCjZ/7ebIj8 6bRDFsXuQ7FeSlSA5g9nWDISlsTzpwo= =jmSh -----END PGP SIGNATURE-----