Re: < "$@" doesn't expand properly?

Marc Chantreux <[email protected]> Sat, 4 Oct 2025 08:55:47 +0200
Newsgroups org.kernel.vger.dash
Message-ID <aODE8547kOvhQPIf@prometheus>
Hi Lawrence,

> POSIX leaves this unspecified.  Section 2.7 [1] says that field
> splitting is not performed on the word following a redirection
> operator, and section 2.5.2 [2] says that the expansion of "$@" is
> unspecified in that context.

wow ... thank you so much for digging this. this is the second time
this year where oppose POSIX standard against consistency and ease of
use.

I can understand why because most of the scripts I learned with were
postfixing the redirections so word splitting doesn't matter at this
point but prefixing the < is really a matter of easing the readability
and maintainance:

	< A B | C | D > E

is much better for your brain than

	B < A | C | D > E

> Almost no shell works the way you are expecting, except for zsh in
> native mode (which I suspect is where you first tried this syntax)

Not at all. Actually dash is not only the more lightweight shell I
know but also the one which behave as close as what I expect from a
POSIX shell so it became my first choice when it comes to scripting.

No shell behave the way I would like (for example, none but zsh
allow prefixed redirections to compound expressions) to but the closest
are by far rc, dash and zsh.

> 	% ./bash /tmp/x.sh a b
> 	% dash /tmp/x.sh a b
> 	% ksh /tmp/x.sh a b
> 	% mksh /tmp/x.sh a b
> 	% oksh /tmp/x.sh a b
> 	% yash /tmp/x.sh a b
> 	% zsh /tmp/x.sh a b

I see we have the same shells in the scope. I just dropped bash from my
radar because its competitor (heavy but feature oriented) is way better
so I keep telling people to use zsh instead.

when in comes to the ratio (needed_features / kb), dash is gold.

>   [1] https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/V3_chap02.html#tag_19_07
>   [2] https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/utilities/V3_chap02.html#tag_19_05_02

As the behavior is undefined, of course, I would like to propose to
behave the most helpful way when it makes sense because

* the other usecases are already doable:
	* if the expected behavior is "$*", so use "$*"
	* what's the point of A  < "$@" ? use "$1" instead
* it's a matter of consistency to me. why "$@" can't behave as "$@" ?

Again, thank you so much for such a precise and useful answer.
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+1WAUCaODE7gAKCRC+er2aYc+1
WMQ8AP9dSi54mXkNXv96E0h5WNPZHFGjpB8bDc6oR4bFN1BeNQEA5HOk+agnyroS
Is7i5lB/HfVBT5voQeb2dglKR9oXuws=
=Izx/
-----END PGP SIGNATURE-----