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: Sun, 5 Oct 2025 09:21:27 +0200	[thread overview]
Message-ID: <aOIcd2VviROi95Wj@prometheus> (raw)
In-Reply-To: <cff17249-7e9d-47f9-aca1-ef1bfa5cd32a@app.fastmail.com>

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

Hi Lawrence,

On Sat, Oct 04, 2025 at 11:13:51AM -0400, Lawrence Velázquez wrote:
> Sure it does.  Redirections can be infixed, so these are all valid:
> 
> 	<file cmd arg

my prefered one by far

> 	cmd arg <file

The one i kept using for years just because examples use it while isn't
now my most hated by far. a good demonstration about reading the man
pages even if you think you know the tool.

> 	cmd <file arg

> Someone who agrees with your argument should logically expect this
> to "work":
> 
> 	set file arg
> 	cmd < "$@"

I have to admit I forgot this one because I considered it confusing and
useless but thanks to your example, I realize today is a convenient way to
place the data source in "$1" instead of the top of stack and that could
be useful in dash scripting because where is no simple/rubust way to get
this top (the equivalent of $argv[-1] in zsh). But as "$@" in not
expanded after <, this usecase is wasted as well.

fool() {
	local source="$1"
	echo "content of $source:"
	cat < "$@"
}
fool mind -n

content of mind:
sh: 4: cannot open mind -n: No such file

> >> 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.
> Ah, well.  I guessed so because I know from the zsh mailing lists
> that you're a big zsh fan.

I'm also fan of rc and long time user of mksh, I also used tcsh at the end
of the last millenium and tested any other ones (including exotic ones
like zoidberg and elvish).

I once (~ 10 years ago?) wrote an email to Tom Duff to thank him for rc
ask him why there was no advanced variable expansions in rc (like
${foo#bar}, ${foo?oops} and so on). He answered me that nobody were using
them back then. He also wrote something that has a deep impact of the way
I think about shell scripting:

	«rc means "run commands" and should not do much more»

from this day, I started to bet on external commands much more than
shell internals and realized my scripts where faster and more reliable.

As I didn't need all the zsh features anyore (and rc is sadly too
unknown to be used when you want to share your scripts), dash became my
almost only shebang (also almost all my scripts are working in a bare
busybox chroot, including CGIs).

I keep using zsh for interactive stuff because there is no competitor
on this part of the game thanks to

* "alternate syntax" for control statements
* advanced features like extended globs, list filtering, filename modifiers
* incredible zle widgets

> > 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 "$@" ?
> 
> One could easily make the same "consistency" argument from the
> perspective of the redirection operator.  POSIX disallows this
> expansion from producing multiple fields...
> 
> 	var='foo bar'
> 	cmd < $var
> 
> ...so why should this one produce multiple fields?
> 	set foo bar
> 	cmd < "$@"

from the POSIX perspective, it indeed shouldn't.

> In any case, the existing behavior conforms to POSIX and is far
> more portable, so it is not likely to change.

That's what I learnt from you (again: thank you so much) and
made me so sad: consistency on POSIX compliance avoid consistency around
useful behaviors. On the other hand, I totally support the idea that at
least one shell must be POSIX compatible flaw by flaw.

there is no perfect shell in this world :)

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-05  7:28 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
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 [this message]

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=aOIcd2VviROi95Wj@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