Reputation: 1071
I cannot pinpoint the exact difference between using ${array[@]} vs ${array[*]}
What diff I see is when printing, but I guess there is more to it
declare -a array
array=("1" "2" "3")
IFS=","
printf "%s" ${array[@]}
printf "%s" ${array[*]}
IFS=" "
I searched on TLDP about it, but couldn't figure it out. Is it a general bash thing or just for arrays? Thanks a lot!
Upvotes: 22
Views: 6771
Reputation: 13239
As mentioned in man bash
:
If the word is double-quoted,
${name[*]}
expands to a single word with the value of each array member separated by the first character of theIFS
special variable, and${name[@]}
expands each element of name to a separate word.
Examples:
array=("1" "2" "3")
printf "'%s'" "${array[*]}"
'1 2 3'
printf "'%s'" "${array[@]}"
'1''2''3'
Upvotes: 27