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

    From Charles Curley@3:633/10 to All on Thursday, October 22, 2026 19:00:02
    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/

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Anssi Saari@3:633/10 to All on Friday, October 23, 2026 16:20:02
    The Wanderer <wanderer@fastmail.fm> writes:

    $ echo {1..10}

    , the 'for i in {1..10}; do' is exactly equivalent to 'for i in 1 2 3 4
    5 6 7 8 9 10 ; do'.

    The coolest thing about this brace expansion is that you can even get
    the numbers zero padded for a fixed width, like maybe for filenames or
    tabular data.

    So echo {01..10} outputs 01 02 03 04 05 06 07 08 09 10.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)