I discovered something weird in bash I can't explain. When I initialize an array using the bracket notation with a quoted string (single and double), the string is placed as the first element of the array. When I put the string in a variable and I do the same withe the variable, the string is split properly delimited by IFS.
#/bin/bash
test1="hello my name is mr nobody"
array1=($test1)
test2='hello my name is mr nobody'
array2=($test2)
array3=("Hello my name is mr nobody")
array4=('Hello my name is mr nobody')
declare -p array1
declare -p array2
declare -p array3
declare -p array4
The output:
declare -a array1='([0]="hello" [1]="my" [2]="name" [3]="is" [4]="mr" [5]="nobody")'
declare -a array2='([0]="hello" [1]="my" [2]="name" [3]="is" [4]="mr" [5]="nobody")'
declare -a array3='([0]="Hello my name is mr nobody")'
declare -a array4='([0]="Hello my name is mr nobody")'
What exactly happening, and what is different between the two methods?
array1=( "$test1" )