zsh-users
 help / color / mirror / code / Atom feed
From: "René Neumann" <lists@necoro.eu>
To: zsh-users@zsh.org
Subject: Re: [Review Request] Arrays and their usage
Date: Mon, 31 May 2021 22:04:44 +0200	[thread overview]
Message-ID: <1eb8dc21-eb40-cc32-4ca8-c049d7273a03@necoro.eu> (raw)
In-Reply-To: <20210531173651.2pfklkhv5zizfldg@chazelas.org>

> Here's my take on answering this (repeating some of what has
> already been said).

Greatly appreciated!

> First, I'd say: `...` form of command substitution should really
> be banned these days. That's really a broken heritage from the
> Bourne shell. There's not good reason to keep using it these
> days. The main problem with it is the handling of backslash
> inside it (and the awkward nesting and the fact that it's less
> legible, etc...).

Fun fact: I prefer `...`, because I find it more legible, especially in 
the x=`cmd y z` form¹. But TIL, that `` and $() are not interchangable. 
Up to now, I thought the one is syntactic sugar for the other.

> The sed command could be written:
> 
>    sed -n 's/pkgname = //p'

Good catch, thanks
> Then, leaving `...` (or the better $(...)) unquoted performs
> IFS-splitting, so you're left with the same kind of conundrum as
> you get in POSIX shells when you leave any form of expansion
> ($param, $((arith)) as well there!) unquoted though at least
> zsh doesn't perform globbing there:
> 
> [...]
> 
> pkgs=(
>    ${(f)"$(
>      makepkg --printsrcinfo |
>       sed -n 's/pkgname = //p'
>    )"}
> )

Thank you for this detailed explanation. Not relying on IFS seems a good 
thing to do, although the rest of the script probably does here and there².
Also thanks for this example of code structuring. /me likes.
(NB though: The linebreak for the two pipe elements was inserted for 
this email only, with me hoping, that backslash newline was the correct 
thing to do ;))

> The more idiomatic zsh variant to that ksh syntax would be:
> 
> pkgs=( $DATABASE/$^pkgs )
> 
> (same as rc's pkgs = ( $DATABASE/$pkgs )).

What does 'rc' stand for?

Again, thanks for this effort!

- René

¹ Longer story: $() is easily confused with ${}. Also, `...` is more "in 
the background" and I let my highlighting make it clear to me, that I'm 
in a subcommand. I would always prefer $() in large complex expressions 
though, because.

² Although one could argue that setting IFS to something else than $'\n' 
WILL break a lot of stuff, so one can expect it to be sane.


  reply	other threads:[~2021-05-31 20:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-30 23:24 René Neumann
2021-05-31  0:28 ` Mikael Magnusson
2021-05-31  4:24   ` Bart Schaefer
2021-05-31 19:41   ` René Neumann
2021-05-31 17:36 ` Stephane Chazelas
2021-05-31 20:04   ` René Neumann [this message]
2021-05-31 21:42     ` Bart Schaefer
2021-05-31 21:43     ` Lawrence Velázquez
2021-05-31 22:05       ` René Neumann
2021-06-01  5:59     ` Stephane Chazelas

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=1eb8dc21-eb40-cc32-4ca8-c049d7273a03@necoro.eu \
    --to=lists@necoro.eu \
    --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).