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

Re: Bug? in 'integer' behaviour



`integer z=$(wc -l <"$1")' gives $z = 0:

Bart wrote:
> } I think it's the trailing characters after the number which are causing
> } the problem.  From wc you get something like
> }     128 .zshrc
> 
> No, that can't be right.  Note that input is being redirected to wc, so
> it doesn't produce the trailing file name.

You're quite right, things like "<" aren't so obvious first thing on
Monday morning.  I looked a little further and here's what's
happening:

% showargs() { print -l $*; }
% showargs z=$(wc -l <~/.zshrc)
z=
168

Replace `showargs' by integer and you'll see that the first argument
is z=, so that z gets 0, then the $(...) substitution splits words on
the initial spaces, and the second argument is 168.  I haven't looked
to see what zsh thinks it's doing with `integer 168', but the
word-splitting here does seem to be standard Bourne/Korn shell
behaviour.

So the real workaround is

integer "z=$(wc -l <$1)"

or

integer z
z=$(wc -l <"$1")

It's a little confusing that the argument to an `integer' isn't
handled the same as a straight assignment, but I don't see a way
around.

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy



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