# expr

**URL:** <https://community.unix.com/t/expr/147908>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [January 22, 2004, 8:26am UTC](https://community.unix.com/t/expr/147908 "2004-01-22T08:26:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathe](https://community.unix.com/letter_avatar/nathe/32/6_22734026db12803ebb3e059622ac3534.png) [@Nathe](https://community.unix.com/u/Nathe)\
**Post date:** [January 22, 2004, 8:26am UTC](https://community.unix.com/t/expr/147908/1 "2004-01-22T08:26:55Z")

</div>

Hello!

I want to evaluate some mathematical expressions in a script and I try to use 'expr' command.  
Unfortunatally, when I have, for example,  
expr 8.2 + 6  
the result is 'expr: non-numeric argument'  
Why ?  
I work on SunOs 5.7.

Thanks in advance  
Nathe

---

<div class="post-metadata">

**Author:** ![cbkihong](https://community.unix.com/letter_avatar/cbkihong/32/6_22734026db12803ebb3e059622ac3534.png) [@cbkihong](https://community.unix.com/u/cbkihong)\
**Post date:** [January 22, 2004, 8:47am UTC](https://community.unix.com/t/expr/147908/2 "2004-01-22T08:47:57Z")

</div>

Seems like expr only accepts integers as operands.

---

<div class="post-metadata">

**Author:** ![Nathe](https://community.unix.com/letter_avatar/nathe/32/6_22734026db12803ebb3e059622ac3534.png) [@Nathe](https://community.unix.com/u/Nathe)\
**Post date:** [January 22, 2004, 9:03am UTC](https://community.unix.com/t/expr/147908/3 "2004-01-22T09:03:46Z")

</div>

but when I read the man of expr, it's written:  
DESCRIPTION  
Concatenates arg's (adding separator spaces between them),  
evaluates the result as a Tcl expression, and returns the  
value. The operators permitted in Tcl expressions are a  
subset of the operators permitted in C expressions, and they  
have the same meaning and precedence as the corresponding C  
operators. Expressions almost always yield numeric results  
(integer or floating-point values). For example, the  
expression  
expr 8.2 + 6  
evaluates to 14.2. Tcl expressions differ from C expres-  
sions in the way that operands are specified. Also, Tcl  
expressions support non-numeric operands and string com-  
parisons.

So it should work, no ?

---

<div class="post-metadata">

**Author:** ![cbkihong](https://community.unix.com/letter_avatar/cbkihong/32/6_22734026db12803ebb3e059622ac3534.png) [@cbkihong](https://community.unix.com/u/cbkihong)\
**Post date:** [January 22, 2004, 9:12am UTC](https://community.unix.com/t/expr/147908/4 "2004-01-22T09:12:29Z")

</div>

What shell scripting are you trying to write actually? It sounds from the first post that you are writing a plain sh-like scripting using expr(1), but the manpage you quoted is a TCL manpage that describes expr in TCL, which accepts floating point arithmetic. If you are not dealing with TCL at all then you have simply read the wrong manpage.

---

<div class="post-metadata">

**Author:** ![Nathe](https://community.unix.com/letter_avatar/nathe/32/6_22734026db12803ebb3e059622ac3534.png) [@Nathe](https://community.unix.com/u/Nathe)\
**Post date:** [January 22, 2004, 9:46am UTC](https://community.unix.com/t/expr/147908/5 "2004-01-22T09:46:35Z")

</div>

Well, I think you are right... I try to write a csh script. I don't know why I have the TCL notice for expr instead of sh one. I work in a standard cmdtool window...

Thank you  
Nathe

---

<div class="post-metadata">

**Author:** ![fpmurphy](https://community.unix.com/user_avatar/community.unix.com/fpmurphy/32/110_2.png) [@fpmurphy](https://community.unix.com/u/fpmurphy)\
**Post date:** [January 22, 2004, 6:49pm UTC](https://community.unix.com/t/expr/147908/6 "2004-01-22T18:49:13Z")

</div>

expr does not support floating point numbers.

One way around this is to use a shell that does support  
floating point calculations. One such shell is ksh93. Another  
is bash.

Another way is to make use of the bc(1) utility e.g.

```
result=\`echo"8.2 \+ 6" | bc\`

```

- Finnbarr
