Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: for x in * evaluates filenames as arithmetic expressions?



Yes, that was indeed the case. I used `x' in an arithmetic for-loop earlier. 
However, I didn't realize that this would implicitly impose a `sticky' type 
for the variable. Now that I know, I'll be more careful in the future.

Many thanks for the instant reply,
  Andreas

On Tuesday 24 May 2005 12:51, you wrote:
> Einar Huginson wrote:
> > When executed in a directory containing files with names such as
> >
> > 	2004-10-22.txt
> > 	2004-10-29.txt
> > 	...
> >
> > a ZSH command of
> >
> > 	for x in *
> > 	do
> > 		echo $x
> > 	done
> >
> > fails with
> >
> > 	zsh: bad math expression: operator expected at `txt'
>
> This means that the shell thinks x is an integer variable.  Check this
> with
>
>   print ${(t)x}
>
> Use
>
>   typeset +i x
>
> to revert it to a scalar.  On the command line, simply "unset x" would
> be good enough.
>
> Obviously, you'll have to check what you've been doing to see why
> it would have become an integer.  It certainly wouldn't do that because
> of a "for" loop.  If you've still got the old command list associated
> with x we can probably work it out.



Messages sorted by: Reverse Date, Date, Thread, Author