zsh-workers
 help / color / mirror / code / Atom feed
* typeset question
@ 1997-10-09 10:10 Bernd Eggink
  1997-10-09 11:53 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Bernd Eggink @ 1997-10-09 10:10 UTC (permalink / raw)
  To: zsh-workers mailing list

I'm confused... These two statements work fine and give the same
results:

	typeset x=(a b c)

	x=($(cat file))

where file contains the lines 

	a
	b
	c

But this one does _not_ work:

	typeset x=($(cat file))
Output:
	zsh: not an identifier: c)

Am I missing something or is this a bug? If it's a bug, it's there at
least since 3.0.2

Bernd

--
Bernd Eggink
Regionales Rechenzentrum der Uni Hamburg
eggink@rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html


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

* Re: typeset question
  1997-10-09 10:10 typeset question Bernd Eggink
@ 1997-10-09 11:53 ` Peter Stephenson
  1997-10-09 13:23   ` Bernd Eggink
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 1997-10-09 11:53 UTC (permalink / raw)
  To: Zsh hackers list, Bernd Eggink

Bernd Eggink wrote:
> I'm confused... These two statements work fine and give the same
> results:
> 
> 	typeset x=(a b c)
> 
> 	x=($(cat file))

Actually, the first is not an array assignment; there is nothing
syntactically special about the parentheses in a typeset statement.
(In fact, it does grouping in all statements, to make globs using
parentheses work sensibly, which is why the spaces don't separate words,
but even so typeset just gets the string `x=(a b c)').  You should find
x contains the string '(a b c)'.

> But this one does _not_ work:
> 
> 	typeset x=($(cat file))
> Output:
> 	zsh: not an identifier: c)

As the outer (...) is not special, the $(cat file) splits the thing
into three arguments: x=(a, b and c).  typeset complains about the last
one.

The fix is to do `typeset x' first, then the array assignment to x in
a separate statement.

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, Platanenallee 6, 15738 Zeuthen, Germany.


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

* Re: typeset question
  1997-10-09 11:53 ` Peter Stephenson
@ 1997-10-09 13:23   ` Bernd Eggink
  0 siblings, 0 replies; 3+ messages in thread
From: Bernd Eggink @ 1997-10-09 13:23 UTC (permalink / raw)
  To: zsh-workers mailing list; +Cc: Peter Stephenson

Peter Stephenson wrote:
> 
> Bernd Eggink wrote:
> > I'm confused... These two statements work fine and give the same
> > results:
> >
> >       typeset x=(a b c)
> >
> >       x=($(cat file))
> 
> Actually, the first is not an array assignment; there is nothing
> syntactically special about the parentheses in a typeset statement.
> (In fact, it does grouping in all statements, to make globs using
> parentheses work sensibly, which is why the spaces don't separate words,
> but even so typeset just gets the string `x=(a b c)').  You should find
> x contains the string '(a b c)'.

My confusion was caused by a curious property of 'typeset'. If the
variable 
is already defined as a normal variable, and if it is an array, typeset 
does _nothing_. In all other cases it works as expected. Try this:

	x=a
	typeset x=b	
	print $x	# prints: b

OK... Now try

	unset x
	x=(a b c)
	typeset x=(x y z)
	print $x	# prints: a b c

The contents of the brace gets evaluated, but no assignment takes place.
Bug or 
feature? It's not documented nor does it make sense to me. 

--
Bernd Eggink
Regionales Rechenzentrum der Uni Hamburg
eggink@rrz.uni-hamburg.de
http://www.rrz.uni-hamburg.de/eggink/BEggink.html


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

end of thread, other threads:[~1997-10-09 13:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-09 10:10 typeset question Bernd Eggink
1997-10-09 11:53 ` Peter Stephenson
1997-10-09 13:23   ` Bernd Eggink

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