* "joining" an array with tabs (default is space)
@ 2008-12-09 19:27 Webb Sprague
2008-12-09 19:40 ` Peter Stephenson
2008-12-10 7:00 ` Stephane Chazelas
0 siblings, 2 replies; 5+ messages in thread
From: Webb Sprague @ 2008-12-09 19:27 UTC (permalink / raw)
To: zsh-users
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.
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: "joining" an array with tabs (default is space)
2008-12-09 19:27 "joining" an array with tabs (default is space) Webb Sprague
@ 2008-12-09 19:40 ` Peter Stephenson
2008-12-09 19:47 ` Webb Sprague
2008-12-10 7:00 ` Stephane Chazelas
1 sibling, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2008-12-09 19:40 UTC (permalink / raw)
To: zsh-users
On Tue, 9 Dec 2008 11:27:38 -0800
"Webb Sprague" <webb.sprague@gmail.com> wrote:
> 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.
${(pj.\t.)array}
It's a bit cryptic, but the documentation is there under "Parameter
Expansion Flags" in the zshexpn manual.
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: "joining" an array with tabs (default is space)
2008-12-09 19:27 "joining" an array with tabs (default is space) Webb Sprague
2008-12-09 19:40 ` Peter Stephenson
@ 2008-12-10 7:00 ` Stephane Chazelas
2008-12-10 13:05 ` Stephane Chazelas
1 sibling, 1 reply; 5+ messages in thread
From: Stephane Chazelas @ 2008-12-10 7:00 UTC (permalink / raw)
To: Webb Sprague; +Cc: zsh-users
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: "joining" an array with tabs (default is space)
2008-12-10 7:00 ` Stephane Chazelas
@ 2008-12-10 13:05 ` Stephane Chazelas
0 siblings, 0 replies; 5+ messages in thread
From: Stephane Chazelas @ 2008-12-10 13:05 UTC (permalink / raw)
To: Webb Sprague, zsh-users
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-12-10 13:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-09 19:27 "joining" an array with tabs (default is space) Webb Sprague
2008-12-09 19:40 ` Peter Stephenson
2008-12-09 19:47 ` Webb Sprague
2008-12-10 7:00 ` Stephane Chazelas
2008-12-10 13:05 ` Stephane Chazelas
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).