0

I'm trying to create an array within a bash script. I am doing this:

#!/bin/bash
declare -a testArray1=('a/b/c.def -x -y -z','x/y/z.000 -a -b -c')

echo "testArray1[0] = ${testArray1[0]}"
echo "testArray1[1] = ${testArray1[1]}"

But it doesn't work. Everything is being added to a single [0] element for the array.

What am I doing wrong?

2
  • 1
    Use space instead of , as element separator. Commented Jan 8, 2016 at 10:48
  • simple when you know how. . . Cheers, Commented Jan 8, 2016 at 11:01

1 Answer 1

2

Use this instead:

declare -a testArray1=('a/b/c.def -x -y -z' 'x/y/z.000 -a -b -c')

BTW: you can check the array structure with declare -p, see:

$ declare -a testArray1=('a/b/c.def -x -y -z','x/y/z.000 -a -b -c')
$ declare -p testArray1
declare -a testArray1='([0]="a/b/c.def -x -y -z,x/y/z.000 -a -b -c")'
$
$ declare -a testArray1=('a/b/c.def -x -y -z' 'x/y/z.000 -a -b -c')
$ declare -p testArray1
declare -a testArray1='([0]="a/b/c.def -x -y -z" [1]="x/y/z.000 -a -b -c")'

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.