On Mon, Oct 26, 2026 at 20:59:39 +0100, john doe wrote:
> On 10/26/26 8:20 PM, Franco Martelli wrote:
> > On 26/10/26 at 19:38, Greg Wooledge wrote:
> > > On Mon, Oct 26, 2026 at 19:21:48 +0100, Franco Martelli wrote:
> > > > As usual thanks Greg for the clarifications. I'm still playing
> > > > with
> > not output, as input to populate the array, John Doe suggested:
> > 
> > playlist=($(printf "%d\n" {001..136}))
> > 
> "playlist=($(printf "%s\n" {001..136}))" looks to be a tad better!

They're both insane.  Neither one makes any sense!

An array *does not contain a newline-delimited string of data*.  It
contains string elements, and each string element is pointed to by
a non-negative integer index.

Consider these arrays:

    a=( 1 2 3 4 )
    b=( $(echo "1 2 3 4") )
    c=( $(printf '%s\n' {1..4}) )

What are the differences among them?

It's a trick question!  There are no differences!  After running those
lines of code, we have:

hobbit:~$ declare -p a b c 
declare -a a=([0]="1" [1]="2" [2]="3" [3]="4")
declare -a b=([0]="1" [1]="2" [2]="3" [3]="4")
declare -a c=([0]="1" [1]="2" [2]="3" [3]="4")

They're identical.

If you're populating an array using Word Splitting applies to a Command
Substitution (which is what b and c are using), it doesn't *matter*
whether the string elements are separated by spaces, tabs, or newlines.
Word Splitting treats them all the same.

Look at the assignment of c in detail.  We have an inner command (inside
the Command Substitution) of

    printf '%s\n' {1..4}

This generates the following string of characters:

1
2
3
4

When Word Splitting is done on this string, the results are the words
1, 2, 3, and 4.  So, those become the array's elements.  It's exactly
the same as if you had done:

    c=(
    1
    2
    3
    4
    )

(Yes, that is valid syntax.)  You get the same array in the end.

So my question remains: *why* do you want a newline-delimited string
of numbers?

Reply via email to