I'm trying to assign an array of three values to a variable if it hasn't been assigned yet with the line
: ${SEAFILE_MYSQL_DB_NAMES:=(ccnet-db seafile-db seahub-db)}
Unfortunately, echoing ${SEAFILE_MYSQL_DB_NAMES[@]} results in (ccnet-db seafile-db seahub-db) and ${SEAFILE_MYSQL_DB_NAMES[2]} prints nothing. It seems, the value has been interpreted as a string and not as an array. Is there any way I can make my script assign an array this way?
GNU bash, version 4.3.42(1)-releaseand it did not work the way you said you expect/saw. That all said I'm not sure that I would even expect this to work in the first place. Array assignment isn't the same as the:=/=expansion.:=/=expansion"? I would assume that assigning a value in the default value construct acts the same as when simplly assigning it the normal way (i.e.SEAFILE_MYSQL_DB_NAMES=(ccnet-db seafile-db seahub-db)results in an array variable):=expansion is not the same as a simple assignment. There's no reason to assume that they have to work the same way. Normal array assignment is a specific "compound assignment" nothing says that the:=expansion needs to support the same compound assignment. It certainly could work that way but I don't think it is a necessary assumption/extension that it would.bash;x=(1 2 3)is just special syntax for repeated assignments to indexed names, not the assignment of a single special value to the namex.