In my bash script I'm including an array of other files required by the program. I then print those in the help description. When I used printf for their output, I got results I was not expecting. I have read that the form ${array[@]} is generally preferred as the default for expansion, so I started with that.
My array declaration:
scriptDependencies=("script1.sh" "script2.sh")
And the (initial) printf command:
printf "Dependencies: %s\n" "${scriptDependencies[@]}"
What I got as output:
Dependencies: script1.sh
Dependencies: script2.sh
Although I believe I understand a basic difference between the subscripts '@' and '*' to be all individual elements vs all elements grouped together, I was not expecting two separate lines to print.
When I switched the printf command to use the ${scriptDependencies[*]} form, a single line (closer to what I desired) was printed:
Dependencies: script1.sh script2.sh
Is this expected behavior of printf, and of the subscripts? Or does it point to a problem with printf?
I'm using GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15).