coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: expr shouldn't use spaces


From: David Chmelik
Subject: Re: expr shouldn't use spaces
Date: Mon, 19 Dec 2022 12:24:12 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1

On 12/19/22 10:01 AM, Bernhard Voelker wrote:
On 12/19/22 09:30, dchmelik@gmail.com wrote:
Lately I read about the expr command, which I'm arguing is programmed
wrong for only working right when you put spaces into expressions rather
than working for standard mathematical expressions, which don't use
spaces.  Think back to your mathematics classes: any instructor that
knows what they're doing doesn't use spaces in expressions.  You don't
use spaces in graphing calculators.  You don't use spaces in similar
mathematics software. It's just not the proper writing style. Expr
should be switched around or at least configurable to how mathematicians
and older programmers write versus letting people go with the fad of
younger programmers who forgot maths classes and write for unnecessaru
'readability' which actually also looks worse and begins to take up too
much space.

`expr` is a very old tool, and POSIX defines the syntax that tool allows:

 https://pubs.opengroup.org/onlinepubs/9699919799/utilities/expr.html

Hence, we have to care more about compatibility rather than allowing
newer or fancier input syntax.
In this case /POSIX/ has the new/fancy syntax breaking millennia tradition... I understand POSIX should be followed, but because of this, now I don't trust them on virtually anything, and many tools are extended/configurable to do more than what POSIX does, which I don't see what would be wrong with that.

The above POSIX page already states:

 In many cases, the arithmetic and string features provided as part
 of the shell command language are easier to use than their equivalents
 in expr. Newly written scripts should avoid expr in favor of the new
 features within the shell

If the shell arithmetic is not sufficient, then I'd recommend bc(1).
Thanks!  I was looking for that.  I don't know whether bc or calc is better...




reply via email to

[Prev in Thread] Current Thread [Next in Thread]