public inbox for dash@vger.kernel.org
 help / color / mirror / Atom feed
From: Marc Chantreux <mc@unistra.fr>
To: "Lawrence Velázquez" <vq@larryv.me>
Cc: dash@vger.kernel.org
Subject: Re: < "$@" doesn't expand properly?
Date: Sat, 4 Oct 2025 08:55:47 +0200	[thread overview]
Message-ID: <aODE8547kOvhQPIf@prometheus> (raw)
In-Reply-To: <5a1befb9-0617-40b0-9c53-7bf6452f0dcd@app.fastmail.com>

[-- Attachment #1: Type: text/plain, Size: 2494 bytes --]

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


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2025-10-04  6:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-03 22:47 < "$@" doesn't expand properly? Marc Chantreux
2025-10-03 23:31 ` Lawrence Velázquez
2025-10-04  6:55   ` Marc Chantreux [this message]
2025-10-04 11:42     ` Harald van Dijk
2025-10-04 13:31       ` Marc Chantreux
2025-10-04 15:13     ` Lawrence Velázquez
2025-10-05  7:21       ` Marc Chantreux

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aODE8547kOvhQPIf@prometheus \
    --to=mc@unistra.fr \
    --cc=dash@vger.kernel.org \
    --cc=vq@larryv.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox