On Mon, Sep 4, 2017 at 8:27 AM, Greg Reagle <greg.rea...@umbc.edu> wrote:
> On Mon, Sep 4, 2017, at 11:04, Kurtis Rader wrote:
> > Beware `expr`s automatic coercion of strings to ints. If you do `expr
> '234 < 1234' you'll
> > get false despite "234" being lexically greater than "1234". Which may
> be what you want but
> > it's a potential gotcha if you really wanted a string, not int,
> comparison.
>
> I think you made a mistake or typo there. You'll get true. But I see
> your point, and it's a good point. What about doing
> expr a$v1 '<' a$v2
> to force them to be interpreted as strings? Any gotchas there?
Yes, the first operand was supposed to be "123". Note, too, that you can't
quote the entire expression like I did. So much for typing a reply off the
cuff without cutting/pasting to make sure it works as expected. Each token
has to be a separate argument. Which is another potential gotcha. From the
man page:
> All operators and operands must be passed as separate arguments.
So you can't type `expr "$v1 * $v2"`. You have to type `expr $v1 "*" $v2`.
Ugh!
And, yes, your workaround ensures the values are treated as strings and
compared lexicographically since they can't be coerced to ints.
--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users