🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.debian.user
Article #258

Re: Bash: check if a value is into an array

#258
From: Charles Curley
Date: Thu, 22 Oct 2026 17:00
27 lines
4541 bytes
On Thu, 22 Oct 2026 11:43:02 -0400
Greg Wooledge <greg@wooledge.org> wrote:

> On Thu, Oct 22, 2026 at 15:34:59 -0000, CGS wrote:
> > If I select random on a finite song playlist, I wouldn't want the
> > same song playing twice; this would require an algorithm that would
> > deselect songs that have already been chosen. Maybe your code
> > accounted for that (or not).  
> 
> This is covered by keeping track of what's already been selected,
> either in a second array (which is the more efficient way), or by
> traversing the playlist to see if the new selection is already in
> the playlist (the less efficient way).

Another way to prevent repetition is to delete each element from the
array when you play it. This is easy enough to code, but does prevent
you from backtracking.

Another way to get your playlist played randomly and non-repeatably is
to use vlc and have it play randomly within the playlist. I suspect
other players can do similarly.

-- 
Does anybody read signatures any more?

https://charlescurley.com
https://charlescurley.com/blog/
Technical Details
Message-ID: <NR4j0-7dIu-13@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!robomod
References: <NQFND-6ZMU-9@gated-at.bofh.it> <NQG6Z-703J-7@gated-at.bofh.it> <NQJod-71PP-13@gated-at.bofh.it> <NQJxT-71Ty-3@gated-at.bofh.it> <NQJRf-729Y-7@gated-at.bofh.it> <NR33A-7cWF-3@gated-at.bofh.it> <NR3df-7d0H-1@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: Charles Curley <charlescurley@charlescurley.com>
Newsgroups: linux.debian.user
Subject: Re: Bash: check if a value is into an array
Date: Thu, 22 Oct 2026 19:00:02 +0200
Message-ID: <NR4j0-7dIu-13@gated-at.bofh.it>
References: <NQFND-6ZMU-9@gated-at.bofh.it> <NQG6Z-703J-7@gated-at.bofh.it> <NQJod-71PP-13@gated-at.bofh.it> <NQJxT-71Ty-3@gated-at.bofh.it> <NQJRf-729Y-7@gated-at.bofh.it> <NR33A-7cWF-3@gated-at.bofh.it> <NR3df-7d0H-1@gated-at.bofh.it>
X-Mailbox-Line: From debian-user-request@lists.debian.org  Thu Oct 22 16:56:49 2026
Old-Return-Path: <charlescurley@charlescurley.com>
X-Amavis-Spam-Status: No, score=-0.753 tagged_above=-10000 required=5.3
 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
 DKIM_VALID_EF=-0.1, RCVD_IN_BL_SPAMCOP_NET=1.347]
 autolearn=no autolearn_force=no
X-Policyd-Weight: using cached result; rate: -3.5
X-Authority-Analysis: v=2.4 cv=NMzV+16g c=1 sm=1 tr=0 ts=6ada3fbe
 a=NgvI/wQFGgfv1u5PwVnSLQ==:117 a=NgvI/wQFGgfv1u5PwVnSLQ==:17
 a=GaTZcmDnFOukpZ7K:21 a=kj9zAlcOel0A:10 a=660iZSQnnn4A:10 a=x5bAJOVjf1IA:10
 a=UPwgjlzBAAAA:8 a=dZMFJRZpAAAA:8 a=os3_AGKq3tFRtctRtlgA:9 a=CjuIK1q_8ugA:10
 a=IJG1HS28PhTFVN2WG8Av:22 a=0ALrU5orTrKXcsu2oHG6:22 a=77MlUavazzFiBdNJOaXW:22
Organization: occasionally
X-Mailer: Claws Mail 4.3.1 (GTK 3.24.49; x86_64-pc-linux-gnu)
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Antiabuse: This header was added to track abuse, please include it with any abuse report
X-Antiabuse: Primary Hostname - box5635.bluehost.com
X-Antiabuse: Original Domain - lists.debian.org
X-Antiabuse: Originator/Caller UID/GID - [47 12] / [47 12]
X-Antiabuse: Sender Address Domain - charlescurley.com
X-Bwhitelist: no
X-Source-IP: 97.245.236.164
X-Source-L: No
X-Exim-ID: 1xJw3H-00000003rX3-3qG7
X-Source-Sender: 164.sub-97-245-236.myvzw.com (hawk.localdomain) [97.245.236.164]:44906
X-Source-Auth: charlescurley@charlescurley.com
X-Email-Count: 1
X-Org: HG=bhshared;ORG=bluehost;
X-Source-Cap: Y2hhcmxpYTM7Y2hhcmxpYTM7Ym94NTYzNS5ibHVlaG9zdC5jb20=
X-Local-Domain: yes
X-Cmae-Envelope: MS4xfEhC2/Pa28QBo4Lggrrpi3V0Ip09L9/KJg6hFBz5S2PCPYqID/JXVDLsDhgGlrqnlBPitGkdgwsrAgLTAH+ofR9Q3j7sNWStgSd+R9wUD7r7Azr8qbJ1
 tbU9qHQEFTUeEtTGlX3N/jU12ouykTQme1nzV2YdKOMd3xAn4+uUAb0FAapAgHfYuymyhl5bZoTlRrC4p99Rw5FgCm5OlAGZ/WTu+BTZwJo2FxbMb5pUEzLo
X-Mailing-List: <debian-user@lists.debian.org> archive/latest/832570
List-ID: <debian-user.lists.debian.org>
List-URL: <https://lists.debian.org/debian-user/>
List-Archive: https://lists.debian.org/msgid-search/20261022105402.03148c32@hawk.localdomain
Approved: robomod@news.nic.it
Lines: 27
Sender: robomod@news.nic.it
X-Original-Date: Thu, 22 Oct 2026 10:54:02 -0600
X-Original-Message-ID: <20261022105402.03148c32@hawk.localdomain>
X-Original-References: <fb4588c5-2637-4714-81e6-791a9260afbd@gmail.com>
	<20261021150743.GA21484@wooledge.org>
	<b397ac30-dbff-4822-b314-c6cc97dc0df8@gmail.com>
	<atkI_Agk3vuY5vlg@phare.normalesup.org>
	<20261021190728.GB28455@wooledge.org>
	<slrn11dkb93.1hg.etphonehomefrance@einstein.home.arpa>
	<20261022154302.GF28455@wooledge.org>