Article View: linux.debian.user
Article #283Re: Bash: check if a value is into an array
From: Franco Martelli
Date: Fri, 23 Oct 2026 18:20
Date: Fri, 23 Oct 2026 18:20
47 lines
5910 bytes
5910 bytes
On 23/10/26 at 17:36, Greg Wooledge wrote:
>> I've added the "if [ -z "${assigned[rand]}" ]; then" statement because $rand
>> had many occurrences of the same value so I tried with the "assigned[$rand]"
>> array to avoid that, looping in the circumstance "$rand" had a value already
>> assigned.
> It's*fine* if rand gets the same value more than once in this loop.
> It just means that particular slot in the playlist will be swapped
> more than once. It doesn't mean a song will be repeated.
In my understanding I supposed that some clip was left in its original
position (skipped) but now I realize that it is not possible because
"$i" changes for each iteration.
>
> I suspect you don't understand what the original code is doing. I added
> the comments for a reason -- they tell you what each section does.
> I didn't explain every line, because that's not how code comments should
> be used.
I had my coding in my mind. That it encompassed an unique $rand value
necessary as array index to shuffle the playlist[], as I did in my
previous coding. In other words I did a sort of confusion mixing my
previously coding concepts and apply them to your code.
>
> If you need help understanding the original code (e.g. an explanation
> of every single line, one by one), feel free to ask.
>
> Are you stuck on the word "shuffle"? It's normally used with a deck of
> playing cards. If you have a deck of cards, and you shuffle it, then
> the same cards are still in the deck, but they're in a different, random,
> order. You don't magically get two of the same card, unless your deck
> started out with duplicates.
No, I'm OK with the "shuffle" meaning.
>
> That's what this loop is doing. It takes your array of filenames and
> shuffles it. The filenames are randomly re-ordered.
I apologize for the noise, but since I was unsure, I decided to write
you an email, I'll restore the code to its original state.
Kind regards,
--
Franco Martelli
Technical Details
Message-ID:
<NRs1X-7rsn-1@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!news.corradoroberto.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomodReferences:
<NQFND-6ZMU-9@gated-at.bofh.it> <NQG6Z-703J-7@gated-at.bofh.it> <NQJod-71PP-13@gated-at.bofh.it> <NQJRf-729Y-1@gated-at.bofh.it> <NR1br-7bQc-11@gated-at.bofh.it> <NR1XP-7chD-5@gated-at.bofh.it> <NRpnr-7pXh-11@gated-at.bofh.it> <NRpx8-7q12-5@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!news.corradoroberto.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomod
From: Franco Martelli <martellif67@gmail.com>
Newsgroups: linux.debian.user
Subject: Re: Bash: check if a value is into an array
Date: Fri, 23 Oct 2026 20:20:01 +0200
Message-ID: <NRs1X-7rsn-1@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> <NQJRf-729Y-1@gated-at.bofh.it> <NR1br-7bQc-11@gated-at.bofh.it> <NR1XP-7chD-5@gated-at.bofh.it> <NRpnr-7pXh-11@gated-at.bofh.it> <NRpx8-7q12-5@gated-at.bofh.it>
X-Original-To: debian-user@lists.debian.org
X-Mailbox-Line: From debian-user-request@lists.debian.org Fri Oct 23 18:10:07 2026
Old-Return-Path: <martellif67@gmail.com>
X-Amavis-Spam-Status: No, score=-1.849 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001,
RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham autolearn_force=no
X-Policyd-Weight: using cached result; rate: -5.5
X-Gm-Message-State: AFq9FYIHMaclsBet6oTWjAJjexPL64xYYqg4XkZE+oKCoN1N8bNoRAH1
9RMomQk2K1SOe7+hVmbjqDODjbLJBFZQskZLlEgNm0eWLMqn4cG1c92cw86kEA==
X-Gm-Gg: AYBFou2TQbNmBEBxGupxTK5ogVOdQPRrrcnDp1IaVgHL3s4/Znr0xf+Bt/cQ6ZLKROC
vXZ9YRqQ9oX1TTEZrp0pRuqqTseX5T4ea1eVEApPSpjQ/nKtDkUFbjNRic1osz08HmVoC3EtPc9
zGoYxQSvTrfjdme0RF16GJ/s4amJS859yu1wGbYgt0Bf1a0i15hDXn3jNYRnxynNMn3V51c4Zjh
JplpufjgliDsp7B6pRTrk0w4Sdi+i5QgYVIA67Pbqwb9OONcG7jrYY4FnrKd8y3oIrF6Mx8XFD+
gPL7sxUvmMlekuh5JEG69StWEYPq4J+shzUt1oz3jU8x048m/FxY55Q+Ci38/UzQlv1s02cbAp4
krUBDSeB/h/o8pj0Ys4rRyxKVmW7heF3W0k1SCDlrNeoJOdakZNBoLbd2s7eJZRHp6ObWt+KEYi
VqUvgIct7llX34IRcmdrLOD3CD5k/3KX9eEu9i6wUviFAmGecYa4lrbOxoYoBcHVJoMdSTv9YR3
5SvikdUUBK3H8RJEwiyiFLL2s9mcx80/kY9L3Egcv4o37QQAtYo1DsTUaJ5yjiE5kWWiHWlJDcX
BK061cPuJE0r
X-Received: by 2002:a05:600c:c170:b0:4a1:fb01:13 with SMTP id 5b1f17b1804b1-4a21908175bmr27516015e9.18.1792778992652;
Fri, 23 Oct 2026 11:09:52 -0700 (PDT)
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Content-Language: en-US
Autocrypt: addr=martellif67@gmail.com; keydata=
xjMEXwx9ehYJKwYBBAHaRw8BAQdA8CkGKYFI/MK9U3RPhzE5H/ul7B6bHu/4BIhTf6LLO47N
J0ZyYW5jbyBNYXJ0ZWxsaSA8bWFydGVsbGlmNjdAZ21haWwuY29tPsKWBBMWCAA+FiEET9sW
9yyU4uM6QbloXEn0O0LcklAFAmhyroACGwMFCQ0ncuYFCwkIBwIGFQoJCAsCBBYCAwECHgEC
F4AACgkQXEn0O0LcklAHVwD9H5JZ52g292FD8w0x6meDD8y/6KkNpzuaLHP6/Oo8kAIBAJsh
aMB9LdCBJTMtnxU8JTHtAoGOZ/59UJWeZIkuWJUNzjgEXwx9ehIKKwYBBAGXVQEFAQEHQNP5
V2q0H0oiJu89h1SSPgQDtkixXvUvRf1rNLLIcNpPAwEIB8J+BBgWCAAmFiEET9sW9yyU4uM6
QbloXEn0O0LcklAFAmhyroACGwwFCQ0ncuYACgkQXEn0O0LcklASVwEAoEkHMEU7mHc0zmAu
D2R1PYsDh9+3wQeied5PrF+HdakBAOeSGsf40GBew5umZuM59I04d1uXYAXGMP+jGN2RUtMA
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Mailing-List: <debian-user@lists.debian.org> archive/latest/832596
List-ID: <debian-user.lists.debian.org>
List-URL: <https://lists.debian.org/debian-user/>
List-Archive: https://lists.debian.org/msgid-search/133dd7dd-b716-4109-8ade-a45344092a89@gmail.com
Approved: robomod@news.nic.it
Lines: 47
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Date: Fri, 23 Oct 2026 20:09:50 +0200
X-Original-Message-ID: <133dd7dd-b716-4109-8ade-a45344092a89@gmail.com>
X-Original-References: <fb4588c5-2637-4714-81e6-791a9260afbd@gmail.com>
<20261021150743.GA21484@wooledge.org>
<b397ac30-dbff-4822-b314-c6cc97dc0df8@gmail.com>
<20261021190429.GA28455@wooledge.org>
<02f8c2b4-80ec-4f0a-a277-3f1c80acd476@gmail.com>
<20261022142207.GE28455@wooledge.org>
<4ca939f7-efa0-410a-a6a4-bf9d08bc14f4@gmail.com>
<20261023153643.GC7911@wooledge.org>