zsh-users
 help / color / mirror / code / Atom feed
* newline grief
@ 2018-02-10 19:02 Ray Andrews
  2018-02-10 19:36 ` Bart Schaefer
  2018-02-10 19:46 ` Eric Cook
  0 siblings, 2 replies; 11+ messages in thread
From: Ray Andrews @ 2018-02-10 19:02 UTC (permalink / raw)
  To: Zsh Users

I've been through this before, butI can't remember the answer:

$ typeset -m 'var*'
var1='this is var1'
var2='this is var2'
var3='this is var3'

$ for aa in `typeset -m 'var*'`; do
  print ${aa}
done

var1='this
is
var1'
var2='this
is
var2'
var3='this
is
var3'
varis=''
var=''

How do I get each variable to print on one line?  Sorry, I should know this.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: newline grief
  2018-02-10 19:02 newline grief Ray Andrews
@ 2018-02-10 19:36 ` Bart Schaefer
  2018-02-10 19:38   ` Eric Cook
  2018-02-10 19:46 ` Eric Cook
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2018-02-10 19:36 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 177 bytes --]

On Feb 10, 2018 11:34 AM, "Ray Andrews" <rayandrews@eastlink.ca> wrote:


How do I get each variable to print on one line?  Sorry, I should know this.


Double quotes:  "${aa}"

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: newline grief
  2018-02-10 19:36 ` Bart Schaefer
@ 2018-02-10 19:38   ` Eric Cook
  0 siblings, 0 replies; 11+ messages in thread
From: Eric Cook @ 2018-02-10 19:38 UTC (permalink / raw)
  To: zsh-users

On 02/10/2018 02:36 PM, Bart Schaefer wrote:
> On Feb 10, 2018 11:34 AM, "Ray Andrews" <rayandrews@eastlink.ca> wrote:
> 
> 
> How do I get each variable to print on one line?  Sorry, I should know this.
> 
> 
> Double quotes:  "${aa}"
> 
It is already mangled at that point though.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: newline grief
  2018-02-10 19:02 newline grief Ray Andrews
  2018-02-10 19:36 ` Bart Schaefer
@ 2018-02-10 19:46 ` Eric Cook
  2018-02-10 19:54   ` Daniel Shahaf
  2018-02-10 20:36   ` Ray Andrews
  1 sibling, 2 replies; 11+ messages in thread
From: Eric Cook @ 2018-02-10 19:46 UTC (permalink / raw)
  To: zsh-users

On 02/10/2018 02:02 PM, Ray Andrews wrote:
> I've been through this before, butI can't remember the answer:
> 
> $ typeset -m 'var*'
> var1='this is var1'
> var2='this is var2'
> var3='this is var3'
> 
> $ for aa in `typeset -m 'var*'`; do
>  print ${aa}
> done
> 
> var1='this
> is
> var1'
> var2='this
> is
> var2'
> var3='this
> is
> var3'
> varis=''
> var=''
> 
> How do I get each variable to print on one line?  Sorry, I should know this.
> 
> 
for aa in "${(f)$(typeset -m 'var*')}"; do
....

While all of it isn't applicable to zsh: this explains what happened in your case:
http://mywiki.wooledge.org/DontReadLinesWithFor


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: newline grief
  2018-02-10 19:46 ` Eric Cook
@ 2018-02-10 19:54   ` Daniel Shahaf
  2018-02-10 20:09     ` Eric Cook
  2018-02-10 21:04     ` Ray Andrews
  2018-02-10 20:36   ` Ray Andrews
  1 sibling, 2 replies; 11+ messages in thread
From: Daniel Shahaf @ 2018-02-10 19:54 UTC (permalink / raw)
  To: zsh-users

Eric Cook wrote on Sat, 10 Feb 2018 14:46 -0500:
> for aa in "${(f)$(typeset -m 'var*')}"; do

There's an API for this information:

for parameter_name in ${(k)parameters[(I)var*]} ; do


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: newline grief
  2018-02-10 19:54   ` Daniel Shahaf
@ 2018-02-10 20:09     ` Eric Cook
  2018-02-10 21:07       ` Ray Andrews
  2018-02-10 21:04     ` Ray Andrews
  1 sibling, 1 reply; 11+ messages in thread
From: Eric Cook @ 2018-02-10 20:09 UTC (permalink / raw)
  To: zsh-users

On 02/10/2018 02:54 PM, Daniel Shahaf wrote:
> Eric Cook wrote on Sat, 10 Feb 2018 14:46 -0500:
>> for aa in "${(f)$(typeset -m 'var*')}"; do
> 
> There's an API for this information:
> 
> for parameter_name in ${(k)parameters[(I)var*]} ; do
> 
Indeed, my answer was a attempt as explaining how one would loop over lines of output
from a command substitution; not a example of the best way to do what it appears
that he wants.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: newline grief
  2018-02-10 19:46 ` Eric Cook
  2018-02-10 19:54   ` Daniel Shahaf
@ 2018-02-10 20:36   ` Ray Andrews
  1 sibling, 0 replies; 11+ messages in thread
From: Ray Andrews @ 2018-02-10 20:36 UTC (permalink / raw)
  To: zsh-users

On 10/02/18 11:46 AM, Eric Cook wrote:
>
> for aa in "${(f)$(typeset -m 'var*')}"; do
> ....
>
> While all of it isn't applicable to zsh: this explains what happened in your case:
> http://mywiki.wooledge.org/DontReadLinesWithFor
>
Thanks Eric, that works fine.  Bart's quoting by itself did not work.  I 
despair of every really understanding -- parsing in my own head -- how 
those syntaxes work.  I got as close as " ..."${(f) ... " but managed to 
drop the ball.  Thanks for that link, I had no idea for loops and while 
loops were really any different internally, is that widely known?

BTW, is there some way to get typeset to print out just the variables, 
not the values?  As I read the doc the '-m' switch seems not to like the 
'-H' or '+' switches, so it seems I can't have the globed variable name 
with no values printed.  It seems an unlikely limitation.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: newline grief
  2018-02-10 19:54   ` Daniel Shahaf
  2018-02-10 20:09     ` Eric Cook
@ 2018-02-10 21:04     ` Ray Andrews
  2018-02-10 21:36       ` Daniel Shahaf
  1 sibling, 1 reply; 11+ messages in thread
From: Ray Andrews @ 2018-02-10 21:04 UTC (permalink / raw)
  To: zsh-users

On 10/02/18 11:54 AM, Daniel Shahaf wrote:
> Eric Cook wrote on Sat, 10 Feb 2018 14:46 -0500:
>> for aa in "${(f)$(typeset -m 'var*')}"; do
> There's an API for this information:
>
> for parameter_name in ${(k)parameters[(I)var*]} ; do
>
>
What do you mean "an API"?  Application Program Interface ??  Anyway 
your line solves my problem perfectly:

$ for parameter_name in ${(k)parameters[(I)var*]} ; do set ${parameter_name}=; done

... arbitrary list of variables all nulled.  This could be useful for 
cleaning up after some messy function.

Many thanks.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: newline grief
  2018-02-10 20:09     ` Eric Cook
@ 2018-02-10 21:07       ` Ray Andrews
  0 siblings, 0 replies; 11+ messages in thread
From: Ray Andrews @ 2018-02-10 21:07 UTC (permalink / raw)
  To: zsh-users

On 10/02/18 12:09 PM, Eric Cook wrote:
> Indeed, my answer was a attempt as explaining how one would loop over 
> lines of output
>> from a command substitution; not a example of the best way to do what it appears
>> that he wants.
>>
Both have been most educational, thanks for all of it.  Making method A 
work is good even if method B is better, since one might need method A 
for something else later.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: newline grief
  2018-02-10 21:04     ` Ray Andrews
@ 2018-02-10 21:36       ` Daniel Shahaf
  2018-02-10 22:47         ` Ray Andrews
  0 siblings, 1 reply; 11+ messages in thread
From: Daniel Shahaf @ 2018-02-10 21:36 UTC (permalink / raw)
  To: Ray Andrews, zsh-users

Ray Andrews wrote on Sat, 10 Feb 2018 13:04 -0800:
> On 10/02/18 11:54 AM, Daniel Shahaf wrote:
> > Eric Cook wrote on Sat, 10 Feb 2018 14:46 -0500:
> >> for aa in "${(f)$(typeset -m 'var*')}"; do
> > There's an API for this information:
> >
> > for parameter_name in ${(k)parameters[(I)var*]} ; do
> >
> >
> What do you mean "an API"?  Application Program Interface ??

Yes.  ${parameters} is an interface, as opposed to parsing the output
of `typeset` which isn't designed to be used this way (it's designed to
be eval'd).

> $ for parameter_name in ${(k)parameters[(I)var*]} ; do set $
> {parameter_name}=; done
> 
> ... arbitrary list of variables all nulled.  This could be useful for 
> cleaning up after some messy function.

That will set them to empty.  If you want to unset them you can use
'... do unset ${parameter_name}; done', but at that point just 'unset -m
"var*"' would be equivalent and more efficient.

And you should complain to the author of that function to declare his
variables local, see WARN_CREATE_GLOBAL :-)

Cheers

Daniel


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: newline grief
  2018-02-10 21:36       ` Daniel Shahaf
@ 2018-02-10 22:47         ` Ray Andrews
  0 siblings, 0 replies; 11+ messages in thread
From: Ray Andrews @ 2018-02-10 22:47 UTC (permalink / raw)
  To: zsh-users

On 10/02/18 01:36 PM, Daniel Shahaf wrote:
> 'unset -m "var*"' would be equivalent and more efficient. 
As simple as that!  But I'm glad I now see how to do it the hard way too.



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-02-10 22:47 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-10 19:02 newline grief Ray Andrews
2018-02-10 19:36 ` Bart Schaefer
2018-02-10 19:38   ` Eric Cook
2018-02-10 19:46 ` Eric Cook
2018-02-10 19:54   ` Daniel Shahaf
2018-02-10 20:09     ` Eric Cook
2018-02-10 21:07       ` Ray Andrews
2018-02-10 21:04     ` Ray Andrews
2018-02-10 21:36       ` Daniel Shahaf
2018-02-10 22:47         ` Ray Andrews
2018-02-10 20:36   ` Ray Andrews

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).