I want to limit the change to the separator only to the following echo command not to the shell:
$ myarr=(1 2 3)
$ echo $( IFS="|"; echo "${myarr[@]}" )
1 2 3
Why doesn't the separator work for array expansion? Thanks.
arraybash
I want to limit the change to the separator only to the following echo command not to the shell:
$ myarr=(1 2 3)
$ echo $( IFS="|"; echo "${myarr[@]}" )
1 2 3
Why doesn't the separator work for array expansion? Thanks.
Best Answer
From POSIX, regarding
$*
:To join words with a separator, you will have to use
$*
, or${array[*]}
inbash
:Or, with an array in
bash
:With your code: