Domanda

I wonder , if we can save two values , for example , name and number , in the same array member , for example , i have write the following code to do this :

`array[$count]={$x , 1}`

where $x containe a string , but when i want to print the value that array[$count] have :

`echo "$count - $x1 - ${array[$count]} \n"`

it's give just the first value which is $x

È stato utile?

Soluzione

bash does not have multidimensional arrays, but you can fake it using associative arrays:

$ declare -A array
$ count=5
$ array[$count,name]="foobar"
$ array[$count,value]=1
$ for idx in "${!array[@]}"; do printf "%s\t%s\n" "$idx" "${array[$idx]}"; done
5,value 1
5,name  foobar

This requires bash version 4

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top