All you need is printf. It's the print function - that's its job.
printf '%s\t%s\n' ${array[@]}
You do it like this:
( set -- 12345 56789 98765; for i ; do
eval set -- $(printf '"$%s" ' `seq 2 $#` 1)
echo "$*"
done )
OUTPUT
56789 98765 12345
98765 12345 56789
12345 56789 98765
I didn't need eval - that was dumb. Here's a better one:
( set -- 12345 56789 98765 ;
until [ $((i=i+1)) -gt $# ] ; do
set -- $(s=$1 ; shift ; printf '%s\n' "$@" "$s")
printf '%s ' "$@" ; echo
done)
OUTPUT
56789 98765 12345
98765 12345 56789
12345 56789 98765
And then if you want only two elements you just change it a little bit - one more line:
( set -- 12345 56789 98765 ;
until [ $((i=i+1)) -ge $# ] ; do
set -- $(s=$1 ; shift ; printf '%s\n' "$@" "$s")
v="${v}$(printf '%s ' "$@")"
done ; printf "%s\t%s\n" $v
)
OUTPUT
56789 98765
12345 98765
12345 56789
I do this all of the time, but never the bashisms. I always work with the real shell array so it took a few minutes to get hold of it.
Here's a little script I wrote for another answer:
abc="a b c d e f g h i j k l m n o p q r s t u v w x y z"
for l in $abc ; do {
h= c= ; [ $((i=i+1)) -gt 26 ] && n=$((n+26)) i=
xyz=$(x=${xyz:-$abc} ;\
printf %s\\n ${x#?} $l)
mid=$(set -- $xyz ; eval echo \$$((${#}/4))) ;\
echo "$mid $l" >&2 ;
[ $(((i+n)%${mod=3})) -eq 0 ] && c="$mid" h="${xyz%"$mid"*}"
line="$(printf '%s ' $h $c ${xyz#"$h"})"
printf "%s$(printf %s ${xyz#?}${mid})\n" \
${line} >|/tmp/file$((i+n))
} ; done
This writes to 26 files. They look like this only they increment per file:
bcdefghijklmnopqrstuvwxyzag
ccdefghijklmnopqrstuvwxyzag
dcdefghijklmnopqrstuvwxyzag
ecdefghijklmnopqrstuvwxyzag
fcdefghijklmnopqrstuvwxyzag
gcdefghijklmnopqrstuvwxyzag
hcdefghijklmnopqrstuvwxyzag
icdefghijklmnopqrstuvwxyzag
jcdefghijklmnopqrstuvwxyzag
kcdefghijklmnopqrstuvwxyzag
lcdefghijklmnopqrstuvwxyzag
mcdefghijklmnopqrstuvwxyzag
ncdefghijklmnopqrstuvwxyzag
ocdefghijklmnopqrstuvwxyzag
pcdefghijklmnopqrstuvwxyzag
qcdefghijklmnopqrstuvwxyzag
rcdefghijklmnopqrstuvwxyzag
scdefghijklmnopqrstuvwxyzag
tcdefghijklmnopqrstuvwxyzag
ucdefghijklmnopqrstuvwxyzag
vcdefghijklmnopqrstuvwxyzag
wcdefghijklmnopqrstuvwxyzag
xcdefghijklmnopqrstuvwxyzag
ycdefghijklmnopqrstuvwxyzag
zcdefghijklmnopqrstuvwxyzag
acdefghijklmnopqrstuvwxyzag