This does not work and the array is empty, even though I can print the contents of $CMD_STRING . The only examples I can find of this technique use hard coded values to add to the array like,
LIST=("${LIST[@]}" "stuff1" "stuff2" "stuff3")
I find this kind of example to be a bit annoying because I can't envision many real world examples where I would hard code data to add to an array. At least I think it is far more likely for such data to exist in variables.
Am I using the wrong technique here or do I have the syntax wrong?
Yes it is in a loop. I am trying to accumulate a list of commands to run later.
The post you linked to is interesting. I am sure I have done this kind of thing before, meaning accumulated data in an array from inside a loop. A loop is the most likely place where you would want to push allot of data into a structure. I do remember having some issues with the syntax before since I don't do it very often, but I don't remember it not working. Perhaps it matters where the array is declared. Is this like c++ where a variable declared in {} will not be in scope outside of the {}?
I will try to look for some other scripts where I have this method working.
It also seems that a simple string, rather than an array, might be a simpler approach here. When you get to the point that you want to invoke a command, I would assume that you would want -L 22 -s 0 -r -O -A i -N 100 -n to be eleven separate arguments to that command; not a single argument.