배열을 생성했지만 작동하지 않습니다

배열을 생성했지만 작동하지 않습니다

Bash 스크립트에서 배열을 만들려고 합니다. 나는 이것을하고있다 :

#!/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]}"

그러나 이것은 작동하지 않습니다. 모든 것이 [0]배열의 단일 요소에 추가됩니다 .

내가 뭘 잘못했나요?

답변1

대신 이것을 사용하십시오:

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

그런데: 를 사용하여 배열 구조를 확인할 수 있습니다 declare -p. 다음을 참조하세요.

$ 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")'

관련 정보