Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: "joining" an array with tabs (default is space)
- X-seq: zsh-users 13570
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Webb Sprague <webb.sprague@xxxxxxxxx>, zsh-users@xxxxxxxxxx
- Subject: Re: "joining" an array with tabs (default is space)
- Date: Wed, 10 Dec 2008 13:05:09 +0000
- In-reply-to: <20081210070030.GA4843@xxxxxxxxxxxxxxx>
- Mail-followup-to: Webb Sprague <webb.sprague@xxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <b11ea23c0812091127g19b6b55bqdefd4f30701cddf3@xxxxxxxxxxxxxx> <20081210070030.GA4843@xxxxxxxxxxxxxxx>
On Wed, Dec 10, 2008 at 07:00:30AM +0000, Stephane Chazelas wrote:
> 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.
[...]
Oops, brain is going slow in winter....
I meant "with tabs" above not spaces obviously.
"$*" (quotes are important) joins the elements of the array with
the first character of $IFS (or sticks them together if $IFS is
empty).
> 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
[...]
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author