Article View: linux.debian.user
Article #264Re: Bash: check if a value is into an array
From: Greg Wooledge
Date: Thu, 22 Oct 2026 17:50
Date: Thu, 22 Oct 2026 17:50
18 lines
2455 bytes
2455 bytes
On Thu, Oct 22, 2026 at 13:37:52 -0400, Jeffrey Walton wrote:
> On Wed, Oct 21, 2026 at 12:34 PM Franco Martelli <martellif67@gmail.com> wrote:
> > # Populate playlist array with unique random values
> > while [ "$index" -le "$total" ]; do
> > clip="$(/usr/bin/numrandom /1..$total/)"
> > if [[ ! ${playlist[@]} =~ "$clip" ]]; then # [ -z
> > ${rndarr[clip]} ]; then
> > # rndarr[$clip]=1
> > playlist[$index]=$clip
> > ((index++))
> > fi
> > done
> > ...
>
> The code is broken:
You need to account for line wrapping. The "line" beginning with
${rndarr[clip]} is supposed to be attached to the # [ -z above it.
Technical Details
Message-ID:
<NR55n-7ed7-3@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomodReferences:
<NQFND-6ZMU-9@gated-at.bofh.it> <NR4VH-7e8T-7@gated-at.bofh.it>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod From: Greg Wooledge <greg@wooledge.org> Newsgroups: linux.debian.user Subject: Re: Bash: check if a value is into an array Date: Thu, 22 Oct 2026 19:50:01 +0200 Message-ID: <NR55n-7ed7-3@gated-at.bofh.it> References: <NQFND-6ZMU-9@gated-at.bofh.it> <NR4VH-7e8T-7@gated-at.bofh.it> X-Mailbox-Line: From debian-user-request@lists.debian.org Thu Oct 22 17:44:25 2026 Old-Return-Path: <greg@wooledge.org> X-Amavis-Spam-Status: No, score=-1.9 tagged_above=-10000 required=5.3 tests=[BAYES_00=-1.9] autolearn=ham autolearn_force=no X-Policyd-Weight: using cached result; rate:hard: -4.6 Mail-Followup-To: debian-user@lists.debian.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.10.1 (2018-07-13) X-Mailing-List: <debian-user@lists.debian.org> archive/latest/832576 List-ID: <debian-user.lists.debian.org> List-URL: <https://lists.debian.org/debian-user/> List-Archive: https://lists.debian.org/msgid-search/20261022174412.GH28455@wooledge.org Approved: robomod@news.nic.it Lines: 18 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Date: Thu, 22 Oct 2026 13:44:12 -0400 X-Original-Message-ID: <20261022174412.GH28455@wooledge.org> X-Original-References: <fb4588c5-2637-4714-81e6-791a9260afbd@gmail.com> <CAH8yC8=snY2=+6wjF_h7mFy87yfjqEXgp7AnjxBOYt-dgTdwAg@mail.gmail.com>