zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: "René Neumann" <lists@necoro.eu>
Cc: zsh-users@zsh.org
Subject: Re: [Review Request] Arrays and their usage
Date: Mon, 31 May 2021 02:28:25 +0200	[thread overview]
Message-ID: <CAHYJk3TNk-dPjz=iZwPxBCKpXFvHCxntfTetCdDmvsOehmS-wA@mail.gmail.com> (raw)
In-Reply-To: <26fc6ecd-4a05-e562-7274-ba045df536bf@necoro.eu>

On 5/31/21, René Neumann <lists@necoro.eu> wrote:
> Hi *,
>
> I always feel a little unsure around arrays in zsh. I've currently used
> the following:
>
>     local pkgs=( `makepkg --printsrcinfo | \
>                   sed -n -e 's/pkgname = \(.*\)$/\1/p'` )
>
>     pkgs=(${pkgs/#/"$DATABASE/"})
>     sudo pacman -S $pkgs
>
> Intention: Generate a list of packages, prepend "$DATABASE/", and pass
> each modified package as a separate argument to pacman.
>
> Question: Is this the correct/zshonic way of doing this?
> I personally find the change of behavior by adding ( ) too easy to
> overlook. Is there an alternative with ${(...)}?

I don't know what the exact output of your makepkg pipeline can be,
but unquoted `` will split words on all whitespace, so that is a bit
of a danger. I would probably have written it like this

local pkgs=( ${(f)"$(makepkg --blabla | sed blabla)"} )
sudo pacman -S $DATABASE/$^pkgs

That's assuming that the packages from the pipeline are separated by newlines.

-- 
Mikael Magnusson


  reply	other threads:[~2021-05-31  0:29 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 [this message]
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
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='CAHYJk3TNk-dPjz=iZwPxBCKpXFvHCxntfTetCdDmvsOehmS-wA@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=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).