Allan Xu
Allan Xu

Reputation: 9378

How to multiply decimals using expr

When I run the following command:

expr 1.2 * 13

I get this error:

expr: syntax error: unexpected argument '12'

I expect I am missing a syntax. What is it?

Upvotes: 0

Views: 194

Answers (1)

Fravadona
Fravadona

Reputation: 17290

The asterisk is expanded as a glob, so you'll end-up running something like expr 1.2 file1 file2 13

Also, the shell cannot do arithmetic with floating point numbers floating point arithmetic with the shell isn’t standard:

expr 1.2 \* 13
expr: non-integer argument

You'll need to use a command like bc/awk/etc... or convert your numbers to integers:

echo '1.2 * 13' | bc
15.6

awk 'BEGIN{ print 1.2 * 13 }'
15.6

expr 12 \* 13 / 10
15

Upvotes: 1

Related Questions