From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,NORMAL_HTTP_TO_IP,NUMERIC_HTTP_ADDR, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 233a04ea for ; Sun, 1 Dec 2019 20:08:06 +0000 (UTC) Received: (qmail 14699 invoked by alias); 1 Dec 2019 20:07:58 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 24484 Received: (qmail 15155 invoked by uid 1010); 1 Dec 2019 20:07:58 -0000 X-Qmail-Scanner-Diagnostics: from mail-wr1-f48.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.0/25649. spamassassin: 3.4.2. Clear:RC:0(209.85.221.48):SA:0(-0.8/5.0):. Processed in 1.718363 secs); 01 Dec 2019 20:07:58 -0000 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.221.48 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=qQihB5uDQmtbtz0J5vQsLvRNlhDc+f4DfWcHO9/A1tE=; b=pk33Sc2QuZvz5R6LXijc5UCh3uS+0v63lq0J7WaLAAvBNmgMeCNLSgiO7LesnRtbDE 8HDNFw/7JmrHbp35jaG8jXAiXI+xolhGFAL/LRuGu6L7wvBBvD/R7OeIsxqpqRQ0DIF+ mrLNj1YdAyDpgSh4mXhTIaoxl/rXTaIRiWeuR/oPtfBOHz0AINikyMLOh1MsIzQdk7x6 ediRu+g1LA4m+jywNoN5eUCrfPQ/3xVr1dL0//RH5Kr5qdiOiyHKYJiJH9+USk9W0jXQ KbJvaT3dwHZxT+5U/PYigqWa7ieI7fBYKVm755sF0I3WirbBXf6CF2tX2e8dbYI+BZWA 3qVA== X-Gm-Message-State: APjAAAWACjv8ihi+m/ODEOOZUFAOW/yyXGY1nYZP0ZQ1oEz3Xw3QpvD2 Y2dGeHqGQ1CWir8GrL8SgaGTOri5 X-Google-Smtp-Source: APXvYqyl7NcTQtigzhI4SyMcYLOYR5mDMbu3rKohHi0NEfyUXz+8LisO9CBuHxIIKu4d6xKmLZJ+Lg== X-Received: by 2002:a5d:4e8c:: with SMTP id e12mr49739349wru.109.1575230841520; Sun, 01 Dec 2019 12:07:21 -0800 (PST) Date: Sun, 1 Dec 2019 20:07:19 +0000 From: Stephane Chazelas To: zsh-users@zsh.org Subject: Re: shuffle array Message-ID: <20191201200719.anzbs27c7phgdnmm@chaz.gmail.com> Mail-Followup-To: zsh-users@zsh.org References: <867e3jxtao.fsf@zoho.eu> <20191129064215.GA14095@prometheus.u-strasbg.fr> <8636e7w0w9.fsf__36104.0529723809$1575015640$gmane$org@zoho.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8636e7w0w9.fsf__36104.0529723809$1575015640$gmane$org@zoho.eu> User-Agent: NeoMutt/20180716 2019-11-29 09:19:02 +0100, Emanuel Berg: > Marc Chantreux wrote: > > > print -l $array |shuff|read -A array > > *shuf > > The first two steps work The first two steps (with shuf instead of shuff) only work if array elements don't contain backslashes nor newline and are not empty and the first one doesn't start with "-". > but the result array > seems to have only one element? [...] Yes, that's not what read -A does. You could do things like: array=("${(0@)$(printf '%s\0' "$array[@]" | shuf -z)[1,-2]}") But that would still not work for array elements containing NULs. -- Stephane