De POSIX, sobre $*
:
When the expansion occurs in a context where field splitting will not be performed, the initial fields shall be joined to form a single field with the value of each parameter separated by the first character of the
IFS
variable ifIFS
contains at least one character, or separated by a<space>
ifIFS
is unset, or with no separation ifIFS
is set to a null string.
Para unir palavras a um separador, você precisará usar $*
ou ${array[*]}
em bash
:
$ set -- word1 word2 word3 "some other thing" word4
$ IFS='|'
$ echo "$*"
word1|word2|word3|some other thing|word4
Ou com uma matriz em bash
:
$ arr=( word1 word2 word3 "some other thing" word4 )
$ IFS='|'
$ echo "${arr[*]}"
word1|word2|word3|some other thing|word4
Com seu código:
$ myarr=( 1 2 3 )
$ echo $( IFS="|"; echo "${myarr[*]}" )
1|2|3