shell - Bash: Can the values of an associative array be arrays? What's its syntax? -


I have a transmission table that is stored in a bash file, and I am told that the associative array values The array should be, but I do not even know it is possible:

Assume that I have the file /tmp/conf.bash :

Declare - A Associative = (["foo"] = ("Bar" "Falcon")) When I tried to load it ( source /tmp/conf.bash < / Code> using): I get:

borrajax @ wharrgarbl: ~ # sour Ce /tmp/conf.bash bash: /tmp/conf.bash: Line 2: Syntax error near unexpected token `('bash: / tmp / conf Bash: line 2:` ["foo"] = ("bar" "Bash") 'bash: /tmp/conf.bash: line 3: syntax error near unexpected token') 'bash: /tmp/conf.bash: However, if I create a file:

  Declare -A Associative = (["foo"] = "Bar Barge")  

It works correctly:

  Borrajax @ wharrgarbl: ~ # source /tmp/conf.bash borrajax @ hwharrgarbl: ~ # for the key "$ {! Associative [@]} "; Do \ echo" key: $ key; Value: $ {Associate [$ key]} "; \ Done key: foo; value: bar hawks  

Is there a way to specify that there are values ​​in the Bash script? / P>

As a probability minority, the value of associative array is set-split into fractions and then divide them into one array, but I thought that there is a way of formatting the Bash file so that the phase is unnecessary Yes.

I'm using Bash 4.2.28

Thank you in the Grim.

Value in the array (whether indexed or helpful) can only be the wire < Code> bash helps arrays not to be considered as a data structure, but the second level of quotation is that

  args = ("foo bar" "baz" ) Like some Mycommand "$ {args [@]}"  

passes two arguments, not three, in this scenario for the three, mycommand , nests Hunting is not required, because a little Can only be strings, not as arrays as arguments.


Comments