The first assignment to the array titles
assigns the two strings word1 word2
and word1 word2
to the array.
The second assignment contains an unquoted command substitution. The command in the substitution outputs the single string 'word1 word2' 'word1 word2'
, and, since the substitution is unquoted, the shell will split this string on the characters in $IFS
into words (by default, this variable contains a space, a tab, and a newline).
When the string is split into words, the words generated are 'word1
, word2'
, 'word1
and word2'
(four words). These words are then assigned as individual elements to the array titles
.
This is further explained in the answers to other questions. See for example:
declare -p titles
will show the variabletitles
in a complete and unambiguous way.