Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: "joining" an array with tabs (default is space)



On Tue, Dec 09, 2008 at 11:27:38AM -0800, Webb Sprague wrote:
> Hi all,
> 
> If I set IFS='\t', it works great with read -A LINE.  However I want
> to join the output using '\t' instead of spaces-- is there a simple
> way to do that?  I can write a for loop, or maybe recycle print -f
> "\t%s", or maybe use columns in the print, but I was hoping for a
> super graceful (ie typical zsh) approach.
[...]

Try IFS=$'\t'
Then "${var[*]}" will be joined with spaces. It's the same in
every Bourne-like shell but the Bourne shell (and earlier Almquist
shells)

$ IFS=$'\t'
$ set a b
$ echo "$*" | cat -t
a^Ib
$ a=(a b)
$ echo "${a[*]}" | cat -t
a^Ib

Actually, with zsh (and zsh only) $array is the same as
${array[*]}, so:

$ echo "$a" | cat -t
a^Ib


-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author