coreutils
[Top][All Lists]
Advanced

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

Re: expr shouldn't use spaces


From: Bernhard Voelker
Subject: Re: expr shouldn't use spaces
Date: Mon, 19 Dec 2022 19:01:18 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0

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.
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).

Have a nice day,
Berny



reply via email to

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