zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Counting characters in command output?
Date: Thu, 15 Feb 2024 17:53:18 -0800	[thread overview]
Message-ID: <CAH+w=7brXaXfsCi5wXnYNZgZmKVqis6u3T3bPtQuqCHcbpnqKA@mail.gmail.com> (raw)
In-Reply-To: <CAN=4vMp1gcSbE19cbKoW9JJMs_dVhedbOYrwZRVQjbuEg0rNqw@mail.gmail.com>

Entering this conversation here because it seems to be the point after
which it sort of went off the rails.  Go away for a few days and look
what I get ...

On Tue, Feb 13, 2024 at 10:49 PM Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
>
> On Wed, Feb 14, 2024 at 1:46 AM Mark J. Reed <markjreed@gmail.com> wrote:
> >
> > On Tue, Feb 13, 2024 at 3:41 PM Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
> >>
> >> Process substitution gives you an array. Quote it if you need a scalar.
> >
> > You mean command substitution, but thanks! It wouldn't have
> > occurred to me to put quotes around it to change what the `#` was
> > counting!
>
> Right, command substitution. In my opinion, it's unfortunate that
> command substitution in zsh splits on IFS by default. I wish this
> wasn't the case.

This is a case where original author Paul Falstad chose to stick to
the behavior common to other shells.  In particular ...

In all extent shells at the time, but especially in BSD csh, `command`
(backticks) splits its output into words.
$(command) and `command` are supposed to be equivalent (except for nesting).
Therefore $(command) splits its output into words, as happens in every
other shell.

The only place zsh introduced a distinction from the default splitting
behavior of other shells was in parameter expansion.

> It's not even common that one wants to split command
> output into words.

The presumption is that most uses of `command` and $(command) are in
the argument list of other commands (for example, that every word of
the output is a file name), and that anyone coming to zsh from another
shell (which again at the time was the vast majority of zsh users)
would be confused if that behavior were not preserved for backticks
and therefore also for $(...).

If you're using it in an assignment and not to create an argument
list, it's entirely consistent with the behavior of scalars and arrays
that
   scalar=`command`
suppresses splitting (unless the appropriate option is set!) whereas
   array=(`command`)
does not, and if you don't want the splitting behavior then you have
quoting (or prior assignment) to make your intention clear.

If you want command substitution without word splitting, then in
whatever the next version ends up being called you have
   ${ command }
to do that for you, and I am very sorry that I wasn't around two days
ago to say that.

Just for evidence sake:

$ csh
% ls `echo a b c`
ls: cannot access 'a': No such file or directory
ls: cannot access 'b': No such file or directory
ls: cannot access 'c': No such file or directory


  parent reply	other threads:[~2024-02-16  1:54 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-13 20:38 Mark J. Reed
2024-02-13 20:41 ` Roman Perepelitsa
2024-02-14  0:45   ` Mark J. Reed
2024-02-14  6:49     ` Roman Perepelitsa
2024-02-14 13:56       ` Mark J. Reed
2024-02-14 15:36       ` Ray Andrews
2024-02-14 15:58         ` Mark J. Reed
2024-02-14 16:30           ` Ray Andrews
2024-02-15 14:34             ` Lawrence Velázquez
2024-02-15  9:50         ` Roman Perepelitsa
2024-02-15 14:30           ` Lawrence Velázquez
2024-02-15 15:29             ` Ray Andrews
2024-02-15 16:16               ` Roman Perepelitsa
2024-02-15 16:55                 ` Ray Andrews
2024-02-15 14:53           ` Ray Andrews
2024-02-16  1:53       ` Bart Schaefer [this message]
2024-02-16  4:53         ` Lawrence Velázquez
2024-02-16 18:03           ` Bart Schaefer
2024-02-16 18:38             ` Mark J. Reed
2024-02-16 19:36               ` Bart Schaefer
2024-02-16 19:37             ` Lawrence Velázquez
2024-02-16 21:06               ` Mikael Magnusson

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='CAH+w=7brXaXfsCi5wXnYNZgZmKVqis6u3T3bPtQuqCHcbpnqKA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).