zsh-users
 help / color / mirror / code / Atom feed
* can print but not assign to variable
@ 2022-10-26 21:11 Ray Andrews
  2022-10-26 21:38 ` Roman Perepelitsa
  0 siblings, 1 reply; 8+ messages in thread
From: Ray Andrews @ 2022-10-26 21:11 UTC (permalink / raw)
  To: Zsh Users



  $ print -l (#i)$W/rap
/aWorking/Zsh/Source/Wk/RAP
/aWorking/Zsh/Source/Wk/Rap
/aWorking/Zsh/Source/Wk/rap

$ var=(#i)$W/rap
zsh: bad pattern: #i

I'm not expecting trouble there.  I can make the assignment using " 
var=$( print ... ) ", but still it puzzles me that it's not straightforward.




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

* Re: can print but not assign to variable
  2022-10-26 21:11 can print but not assign to variable Ray Andrews
@ 2022-10-26 21:38 ` Roman Perepelitsa
  2022-10-26 21:49   ` Ray Andrews
  0 siblings, 1 reply; 8+ messages in thread
From: Roman Perepelitsa @ 2022-10-26 21:38 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Wed, Oct 26, 2022 at 11:11 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
>
>
>   $ print -l (#i)$W/rap
> /aWorking/Zsh/Source/Wk/RAP
> /aWorking/Zsh/Source/Wk/Rap
> /aWorking/Zsh/Source/Wk/rap
>
> $ var=(#i)$W/rap

This:

    $ var=( (#i)$W/rap )

Roman.


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

* Re: can print but not assign to variable
  2022-10-26 21:38 ` Roman Perepelitsa
@ 2022-10-26 21:49   ` Ray Andrews
  2022-10-26 21:57     ` Lawrence Velázquez
  0 siblings, 1 reply; 8+ messages in thread
From: Ray Andrews @ 2022-10-26 21:49 UTC (permalink / raw)
  To: zsh-users


On 2022-10-26 14:38, Roman Perepelitsa wrote:
> $ var=( (#i)$W/rap )

:-)

What do you call that construction?  I know "(( ))" and "$(( ))" and 
"$()" but I don't really know that one tho I've used it a few times on 
faith.  As usual, if I knew what it was called I'd read up on it.





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

* Re: can print but not assign to variable
  2022-10-26 21:49   ` Ray Andrews
@ 2022-10-26 21:57     ` Lawrence Velázquez
  2022-10-26 22:07       ` Ray Andrews
  0 siblings, 1 reply; 8+ messages in thread
From: Lawrence Velázquez @ 2022-10-26 21:57 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Wed, Oct 26, 2022, at 5:49 PM, Ray Andrews wrote:
> On 2022-10-26 14:38, Roman Perepelitsa wrote:
>> $ var=( (#i)$W/rap )
>
> :-)
>
> What do you call that construction?  I know "(( ))" and "$(( ))" and 
> "$()" but I don't really know that one tho I've used it a few times on 
> faith.  As usual, if I knew what it was called I'd read up on it.

It's just an array assignment.  See zshparam(1).

You originally attempted to do a simple scalar assignment, for which
globbing is not performed on the right-hand side.

-- 
vq


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

* Re: can print but not assign to variable
  2022-10-26 21:57     ` Lawrence Velázquez
@ 2022-10-26 22:07       ` Ray Andrews
  2022-10-26 22:19         ` Lawrence Velázquez
  0 siblings, 1 reply; 8+ messages in thread
From: Ray Andrews @ 2022-10-26 22:07 UTC (permalink / raw)
  To: zsh-users


On 2022-10-26 14:57, Lawrence Velázquez wrote:
>
>> What do you call that construction?  I know "(( ))" and "$(( ))" and
>> "$()" but I don't really know that one tho I've used it a few times on
>> faith.  As usual, if I knew what it was called I'd read up on it.

Ah!  Yes, I do know that.  Yes, we must force 'var' to become an array.  
Stupid ... when I'm doing it with understanding, I get "( )" just fine, 
but when I don't get the necessity I'm lost :(  Ok, all clear.

Tx Roman and Lawrence.



> It's just an array assignment.  See zshparam(1).
>
> You originally attempted to do a simple scalar assignment, for which
> globbing is not performed on the right-hand side.
>


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

* Re: can print but not assign to variable
  2022-10-26 22:07       ` Ray Andrews
@ 2022-10-26 22:19         ` Lawrence Velázquez
  2022-10-27  0:00           ` Ray Andrews
  0 siblings, 1 reply; 8+ messages in thread
From: Lawrence Velázquez @ 2022-10-26 22:19 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Wed, Oct 26, 2022, at 6:07 PM, Ray Andrews wrote:
> Ah!  Yes, I do know that.  Yes, we must force 'var' to become an array.  
> Stupid ... when I'm doing it with understanding, I get "( )" just fine, 
> but when I don't get the necessity I'm lost :(  Ok, all clear.

Additionally, your original attempt -- var=(#i)$W/rap -- is not
actually parsed as a plain old scalar assignment, but as a command
preceded by a temporary array assignment.  Here is a simpler
demonstration:

	% unsetopt EXTENDED_GLOB
	% fn() { typeset -p var }
	% cmd=fn
	% var=(#i)$cmd
	typeset -g -a var=( '#i' )

With EXTENDED_GLOB enabled, "#i" is treated as a glob, but this
fails because it is an invalid pattern.

	% setopt EXTENDED_GLOB
	% var=(#i)$cmd
	zsh: bad pattern: #i

-- 
vq


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

* Re: can print but not assign to variable
  2022-10-26 22:19         ` Lawrence Velázquez
@ 2022-10-27  0:00           ` Ray Andrews
  2022-10-27  0:36             ` Lawrence Velázquez
  0 siblings, 1 reply; 8+ messages in thread
From: Ray Andrews @ 2022-10-27  0:00 UTC (permalink / raw)
  To: zsh-users


> With EXTENDED_GLOB enabled, "#i" is treated as a glob, but this
> fails because it is an invalid pattern.
>
> 	% setopt EXTENDED_GLOB
> 	% var=(#i)$cmd
> 	zsh: bad pattern: #i
>
I crashed into that.  Sheesh, there's one case where EXTENDED_GLOB is 
limiting.  Very confusing.


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

* Re: can print but not assign to variable
  2022-10-27  0:00           ` Ray Andrews
@ 2022-10-27  0:36             ` Lawrence Velázquez
  0 siblings, 0 replies; 8+ messages in thread
From: Lawrence Velázquez @ 2022-10-27  0:36 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Wed, Oct 26, 2022, at 8:00 PM, Ray Andrews wrote:
>> With EXTENDED_GLOB enabled, "#i" is treated as a glob, but this
>> fails because it is an invalid pattern.
>>
>> 	% setopt EXTENDED_GLOB
>> 	% var=(#i)$cmd
>> 	zsh: bad pattern: #i
>>
> I crashed into that.  Sheesh, there's one case where EXTENDED_GLOB is 
> limiting.  Very confusing.

EXTENDED_GLOB has nothing to do with it.  The problem is that

    var=(#flags)pattern

is not parsed the way you think it should be, and it ends up being
a different command altogether, regardless of the state of
EXTENDED_GLOB.  (Notice that my NO_EXTENDED_GLOB example *does not
work* -- it just quietly does something unintended.)

-- 
vq


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

end of thread, other threads:[~2022-10-27  0:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-26 21:11 can print but not assign to variable Ray Andrews
2022-10-26 21:38 ` Roman Perepelitsa
2022-10-26 21:49   ` Ray Andrews
2022-10-26 21:57     ` Lawrence Velázquez
2022-10-26 22:07       ` Ray Andrews
2022-10-26 22:19         ` Lawrence Velázquez
2022-10-27  0:00           ` Ray Andrews
2022-10-27  0:36             ` Lawrence Velázquez

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