Discussion:
expr say "non integer argument"
j***@jidanni.org
2010-02-18 13:15:59 UTC
Permalink
$ expr 3.1 + 3
expr: non-numeric argument <---say "non integer argument"
$ expr 3.1 + 3b
expr: non-numeric argument
Chris F.A. Johnson
2010-02-18 13:20:32 UTC
Permalink
Post by j***@jidanni.org
$ expr 3.1 + 3
expr: non-numeric argument <---say "non integer argument"
$ expr 3.1 + 3b
expr: non-numeric argument
The expr command's arithmetic only works with integers.

3.1 is not an integer, nor is 3b.

To do calculations with decimal fractions, I recommend awk.
--
Chris F.A. Johnson <http://cfajohnson.com>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
j***@jidanni.org
2010-02-18 13:35:45 UTC
Permalink
Post by j***@jidanni.org
$ expr 3.1 + 3
expr: non-numeric argument <---say "non integer argument"
$ expr 3.1 + 3b
expr: non-numeric argument
CFAJ> The expr command's arithmetic only works with integers.
Yes
CFAJ> 3.1 is not an integer, nor is 3b.
Yes
CFAJ> To do calculations with decimal fractions, I recommend awk.
Yes.
3,1 is numeric!
Chris F.A. Johnson
2010-02-18 13:41:32 UTC
Permalink
Post by j***@jidanni.org
Post by j***@jidanni.org
$ expr 3.1 + 3
expr: non-numeric argument <---say "non integer argument"
$ expr 3.1 + 3b
expr: non-numeric argument
CFAJ> The expr command's arithmetic only works with integers.
Yes
CFAJ> 3.1 is not an integer, nor is 3b.
Yes
CFAJ> To do calculations with decimal fractions, I recommend awk.
Yes.
3,1 is numeric!
But it is NOT an integer, and expr only handles integers.
--
Chris F.A. Johnson <http://cfajohnson.com>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Eric Blake
2010-02-18 13:44:37 UTC
Permalink
Post by Chris F.A. Johnson
Post by j***@jidanni.org
$ expr 3.1 + 3
expr: non-numeric argument <---say "non integer argument"
$ expr 3.1 + 3b
expr: non-numeric argument
The expr command's arithmetic only works with integers.
But that's not his point. The point is that 3.1 is numeric, so the error
could be fine-tuned to state that expr expects integers to make it clear
that numeric but non-integer is the reason for the failure. And I'm
inclined to agree. I see nothing in POSIX that requires the current error
string, or forbids a more specific error string.

jidanni, it would be a two-line patch to expr.c. Would you care to write
such a patch, rather than just complaining?
--
Don't work too hard, make some time for fun as well!

Eric Blake ***@byu.net
j***@jidanni.org
2010-02-18 13:54:30 UTC
Permalink
EB> jidanni, it would be a two-line patch to expr.c. Would you care to write
EB> such a patch, rather than just complaining?

It would be much more efficient for me to just play the role of the bug
reporter here.... trust me. Thanks.
Eric Blake
2010-02-18 14:18:01 UTC
Permalink
Post by j***@jidanni.org
EB> jidanni, it would be a two-line patch to expr.c. Would you care to write
EB> such a patch, rather than just complaining?
It would be much more efficient for me to just play the role of the bug
reporter here.... trust me. Thanks.
You are giving up too easily. Your bug reports would go a LOT further if
you would show some effort behind them. What's so hard about:

sed -i 's/non-numeric/non-integer/' src/expr.c

It results in this diff:

diff --git a/src/expr.c b/src/expr.c
index 048c596..1ebb4b9 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -787,7 +787,7 @@ eval4 (bool evaluate)
if (evaluate)
{
if (!toarith (l) || !toarith (r))
- error (EXPR_INVALID, 0, _("non-numeric argument"));
+ error (EXPR_INVALID, 0, _("non-integer argument"));
if (fxn != multiply && mpz_sgn (r->u.i) == 0)
error (EXPR_INVALID, 0, _("division by zero"));
((fxn == multiply ? mpz_mul
@@ -824,7 +824,7 @@ eval3 (bool evaluate)
if (evaluate)
{
if (!toarith (l) || !toarith (r))
- error (EXPR_INVALID, 0, _("non-numeric argument"));
+ error (EXPR_INVALID, 0, _("non-integer argument"));
(fxn == plus ? mpz_add : mpz_sub) (l->u.i, l->u.i, r->u.i);
}
freev (r);


Now all that's lacking is a changelog-style commit message, and you're done.
--
Don't work too hard, make some time for fun as well!

Eric Blake ***@byu.net
j***@jidanni.org
2010-02-18 14:36:26 UTC
Permalink
$ diff --git
diff: unrecognized option '--git'<--see my next email coming soon.
$ dlocate src/expr.c|wc
0 0 0

Actually at one point I was much more involved.
http://article.gmane.org/gmane.comp.version-control.git/103400

However today its
bash: git: command not found
for me, as I'm intent on taking it easy.
j***@jidanni.org
2010-02-18 14:40:08 UTC
Permalink
$ diff --git
diff: unrecognized option '--git'

I think diff should say at this point "real diff, at least up to year
2010, does not have a --git option, you are probably getting that idea
from git output" or something.

Or ask those git pros for a patch to give diff a --git option, or tell
them that they are overstepping their bounds...
Alfred M. Szmidt
2010-02-18 14:45:52 UTC
Permalink
$ diff --git
diff: unrecognized option '--git'

I think diff should say at this point "real diff, at least up to year
2010, does not have a --git option, you are probably getting that idea
from git output" or something.

That is what it says, though not in so many words. Having an option
for each VS would really be a headache (SCCS, RCS, CVS, hg, darcs,
bzr, tla, git, ...).
j***@jidanni.org
2010-02-18 15:08:25 UTC
Permalink
AMS> That is what it says, though not in so many words. Having an option
AMS> for each VS would really be a headache (SCCS, RCS, CVS, hg, darcs,
AMS> bzr, tla, git, ...).

Well all I know is we then harangue the system administrator for not
installing the latest diff that the other guys are already using... when
in fact they are not using diff at all and diff --git would fail on
their machine too because they have boldly invented a fantasy unlike any
other seen there on the command line...

So maybe there should be a general disclaimer added about some people
spreading false rumors about diff options...
Voelker, Bernhard
2010-02-18 15:31:50 UTC
Permalink
Post by Eric Blake
- error (EXPR_INVALID, 0, _("non-numeric argument"));
+ error (EXPR_INVALID, 0, _("non-integer argument"));
...
Post by Eric Blake
- error (EXPR_INVALID, 0, _("non-numeric argument"));
+ error (EXPR_INVALID, 0, _("non-integer argument"));
Maybe a dumb question:
Why's the error message hardcoded?
Isn't there localization for this error message?

Have a nice day,
Berny
Eric Blake
2010-02-18 20:16:21 UTC
Permalink
Post by Voelker, Bernhard
Post by Eric Blake
- error (EXPR_INVALID, 0, _("non-numeric argument"));
+ error (EXPR_INVALID, 0, _("non-integer argument"));
Why's the error message hardcoded?
It isn't.
Post by Voelker, Bernhard
Isn't there localization for this error message?
Yep - _("...") is the localization. It is a macro that calls gettext, and
gettext does all the work of translating it according to your locale
environment variables.
--
Don't work too hard, make some time for fun as well!

Eric Blake ***@byu.net
Voelker, Bernhard
2010-02-19 08:35:07 UTC
Permalink
Post by Eric Blake
Post by Voelker, Bernhard
Post by Eric Blake
- error (EXPR_INVALID, 0, _("non-numeric argument"));
+ error (EXPR_INVALID, 0, _("non-integer argument"));
Why's the error message hardcoded?
It isn't.
Post by Voelker, Bernhard
Isn't there localization for this error message?
Yep - _("...") is the localization. It is a macro that calls gettext, and
gettext does all the work of translating it according to your locale
environment variables.
so the patch implies that there's already a translation for
"non-integer argument", right?

Have a nice day,
Berny
Jim Meyering
2010-02-19 08:51:40 UTC
Permalink
Post by Voelker, Bernhard
Post by Eric Blake
Post by Voelker, Bernhard
Post by Eric Blake
- error (EXPR_INVALID, 0, _("non-numeric argument"));
+ error (EXPR_INVALID, 0, _("non-integer argument"));
Why's the error message hardcoded?
It isn't.
Post by Voelker, Bernhard
Isn't there localization for this error message?
Yep - _("...") is the localization. It is a macro that calls gettext, and
gettext does all the work of translating it according to your locale
environment variables.
so the patch implies that there's already a translation for
"non-integer argument", right?
No. Once a new translatable string appears in a source file,
it propagates to the po/*.pot file for the next release.
Eric Blake
2010-02-25 15:41:11 UTC
Permalink
Post by Eric Blake
Post by j***@jidanni.org
EB> jidanni, it would be a two-line patch to expr.c. Would you care to write
EB> such a patch, rather than just complaining?
It would be much more efficient for me to just play the role of the bug
reporter here.... trust me. Thanks.
You are giving up too easily. Your bug reports would go a LOT further if
you would show some effort behind them.
Your suggestion wasn't all that bad, but I still stand by my position that
you should do more work than just complain. But I had some time available
while cleaning out my inbox, and I was feeling generous, so I finished the
work and am pushing this:
--
Don't work too hard, make some time for fun as well!

Eric Blake ***@byu.net
Eric Blake
2010-02-25 15:52:23 UTC
Permalink
Post by Eric Blake
Post by Eric Blake
Post by j***@jidanni.org
EB> jidanni, it would be a two-line patch to expr.c. Would you care to write
EB> such a patch, rather than just complaining?
It would be much more efficient for me to just play the role of the bug
reporter here.... trust me. Thanks.
You are giving up too easily. Your bug reports would go a LOT further if
you would show some effort behind them.
Your suggestion wasn't all that bad, but I still stand by my position that
you should do more work than just complain. But I had some time available
while cleaning out my inbox, and I was feeling generous, so I finished the
After first squashing in this, to pass 'make check' again.

diff --git a/tests/misc/expr b/tests/misc/expr
index 10dd1c5..6c4280f 100755
--- a/tests/misc/expr
+++ b/tests/misc/expr
@@ -70,7 +70,7 @@ my @Tests =


# This erroneously succeeded and output `3' before 2.0.12.
- ['fail-a', '3 + -', {ERR => "$prog: non-numeric argument\n"},
+ ['fail-a', '3 + -', {ERR => "$prog: non-integer argument\n"},
{EXIT => 2}],

# This erroneously succeeded before 5.3.1.
--
Don't work too hard, make some time for fun as well!

Eric Blake ***@byu.net
Chris F.A. Johnson
2010-02-18 13:57:38 UTC
Permalink
Post by Eric Blake
Post by Chris F.A. Johnson
Post by j***@jidanni.org
$ expr 3.1 + 3
expr: non-numeric argument <---say "non integer argument"
$ expr 3.1 + 3b
expr: non-numeric argument
The expr command's arithmetic only works with integers.
But that's not his point. The point is that 3.1 is numeric, so the error
could be fine-tuned to state that expr expects integers to make it clear
that numeric but non-integer is the reason for the failure.
My apologies; I should have read it more closely. That'll teach me
to post early in the morning!
Post by Eric Blake
And I'm inclined to agree. I see nothing in POSIX that requires the
current error string, or forbids a more specific error string.
I agree.
--
Chris F.A. Johnson <http://cfajohnson.com>
===================================================================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
j***@jidanni.org
2010-02-18 14:08:03 UTC
Permalink
CFAJ> That'll teach me to post early in the morning!
The problem is that you live in the incorrect timezone :-|
Loading...