It may sound a bit trivial but it actually is quite frustrating: Can anyone explain me this:
[~:user$]expr 3 + 2
6
[~:user$]expr 3 / 2
1
[~:user$]expr 3 * 2
expr: syntax error
When the man page for expr
precisely specifies that ARG1 * ARG2 is arithmetic product of both.
Thanks,
You need to quote the *
, because otherwise the shell attempts file name expansion.
$ expr 3 '*' 2
6
This should be enough:
expr 3 \* 2
@OP, its entirely up to you, but i would still suggest to use shell internal addition operation instead of calling external expr
$ echo $(( 3*2 ))
6
If you require more advance maths operations, use bc(dc) or awk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With