* evaluating a condition
@ 1999-09-12 18:41 Gaspar Bakos
1999-09-12 23:51 ` Bart Schaefer
1999-09-13 7:20 ` Johannes Mähner
0 siblings, 2 replies; 5+ messages in thread
From: Gaspar Bakos @ 1999-09-12 18:41 UTC (permalink / raw)
To: zsh-users
Hi,
As a beginner in zsh, I would have a question concerning an 'if'
structure.
I have the following script, and I would like to print the numbers in the
terminal from ${min} to ${max}, if both of them are smaller than 10.
export min=$3;export max=$4;
if (($[min]<10 && $[max]<10)) then
for i in {${min}..${max}}; do echo $i; done
fi
However, this prints the numbers even if ${max}>10
Can someone help?
Gaspar
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: evaluating a condition
1999-09-12 18:41 evaluating a condition Gaspar Bakos
@ 1999-09-12 23:51 ` Bart Schaefer
1999-09-13 16:35 ` Sweth Chandramouli
1999-09-13 7:20 ` Johannes Mähner
1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 1999-09-12 23:51 UTC (permalink / raw)
To: Gaspar Bakos, zsh-users
On Sep 12, 8:41pm, Gaspar Bakos wrote:
} Subject: evaluating a condition
}
} I have the following script, and I would like to print the numbers in the
} terminal from ${min} to ${max}, if both of them are smaller than 10.
At first I thought you'd found a bug in the math parser, but:
} export min=$3;export max=$4;
} if (($[min]<10 && $[max]<10)) then
^^
There's a metafied space here. I think zsh is interpreting "\240$[max]" as
an identifier; e.g. if max=11, the identifier name is "\240\061\061". That
identifier isn't defined, so it's value is 0 which is always < 10.
} for i in {${min}..${max}}; do echo $i; done
} fi
This is a danger of permitting identifiers to contain non-ascii characters.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: evaluating a condition
1999-09-12 18:41 evaluating a condition Gaspar Bakos
1999-09-12 23:51 ` Bart Schaefer
@ 1999-09-13 7:20 ` Johannes Mähner
1 sibling, 0 replies; 5+ messages in thread
From: Johannes Mähner @ 1999-09-13 7:20 UTC (permalink / raw)
To: Gaspar Bakos; +Cc: zsh-users
Gaspar Bakos wrote:
>
> Hi,
>
> As a beginner in zsh, I would have a question concerning an 'if'
> structure.
>
> I have the following script, and I would like to print the numbers in the
> terminal from ${min} to ${max}, if both of them are smaller than 10.
>
> export min=$3;export max=$4;
> if (($[min]<10 && $[max]<10)) then
> for i in {${min}..${max}}; do echo $i; done
> fi
>
> However, this prints the numbers even if ${max}>10
>
> Can someone help?
>
> Gaspar
What version of zsh are you using?
With zsh 3.1.6, your code works fine
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: evaluating a condition
1999-09-12 23:51 ` Bart Schaefer
@ 1999-09-13 16:35 ` Sweth Chandramouli
1999-09-13 17:22 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Sweth Chandramouli @ 1999-09-13 16:35 UTC (permalink / raw)
To: zsh-users
On Sun, Sep 12, 1999 at 11:51:39PM +0000, Bart Schaefer wrote:
> On Sep 12, 8:41pm, Gaspar Bakos wrote:
> } Subject: evaluating a condition
> }
> } I have the following script, and I would like to print the numbers in the
> } terminal from ${min} to ${max}, if both of them are smaller than 10.
>
> At first I thought you'd found a bug in the math parser, but:
>
> } export min=$3;export max=$4;
> } if (($[min]<10 && $[max]<10)) then
> ^^
> There's a metafied space here. I think zsh is interpreting "\240$[max]" as
> an identifier; e.g. if max=11, the identifier name is "\240\061\061". That
> identifier isn't defined, so it's value is 0 which is always < 10.
??? what?
((...)), at least according to the docs (and as implemented in ksh)
is just another syntax for `let '...''. all the "metafying" (actually,
quoting is unmetafying) does is prevent the shell from interpreting the
space as a word separator; once the string to be evaluated is passed to let,
the space is a space again, and let _should_ (and does, in 3.1.6) simply
ignore it, such that the entire block of code does work.
> } for i in {${min}..${max}}; do echo $i; done
> } fi
>
> This is a danger of permitting identifiers to contain non-ascii characters.
??? okay, what did you do to bart? :)
i assume you meant non-printable and not non-ascii here, though
technically a space is still printable.
one related question that i've long wondered but never about cared
enough to ask: is there a difference between the $[...] and ${...} notations?
-- sweth.
--
Sweth Chandramouli ; <sweth@gwu.edu>
<a href="http://astaroth.nit.gwu.edu/resume/">Will Work For Food.</a>
<a href="http://astaroth.nit.gwu.edu/~sweth/disc.html">*</a>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: evaluating a condition
1999-09-13 16:35 ` Sweth Chandramouli
@ 1999-09-13 17:22 ` Bart Schaefer
0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 1999-09-13 17:22 UTC (permalink / raw)
To: Sweth Chandramouli, zsh-users
On Sep 13, 12:35pm, Sweth Chandramouli wrote:
> Subject: Re: evaluating a condition
> On Sun, Sep 12, 1999 at 11:51:39PM +0000, Bart Schaefer wrote:
> > On Sep 12, 8:41pm, Gaspar Bakos wrote:
> > } export min=$3;export max=$4;
> > } if (($[min]<10 && $[max]<10)) then
> > ^^
> > There's a metafied space here. I think zsh is interpreting "\240$[max]" as
> > an identifier; e.g. if max=11, the identifier name is "\240\061\061". That
> > identifier isn't defined, so it's value is 0 which is always < 10.
> ??? what?
> ((...)), at least according to the docs (and as implemented in ksh)
> is just another syntax for `let '...''. all the "metafying" (actually,
> quoting is unmetafying) does is prevent the shell from interpreting
I said there was a metafied space there: I didn't say zsh metafied it.
There's a "\240" character there in the input; cut'n'paste that through
"cat -v" and you'll see "...10 &&M- $[max]...". This has nothing whatever
to do with zsh's internal "metafication" process.
> > This is a danger of permitting identifiers to contain non-ascii characters.
> ??? okay, what did you do to bart? :)
> i assume you meant non-printable and not non-ascii here, though
> technically a space is still printable.
I meant outside the range 0-127 (decimal), though technically I suppose I
actually meant outside the range 27-126.
> one related question that i've long wondered but never about cared
> enough to ask: is there a difference between the $[...] and ${...} notations?
Yeah. $[...] evaluates ... as a math expression, the same as $((...)).
So really it's completely unnecessary inside ((...)), but I didn't want to
answer too many questions at once.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~1999-09-13 17:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-12 18:41 evaluating a condition Gaspar Bakos
1999-09-12 23:51 ` Bart Schaefer
1999-09-13 16:35 ` Sweth Chandramouli
1999-09-13 17:22 ` Bart Schaefer
1999-09-13 7:20 ` Johannes Mähner
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).