To give you the best experience, this site uses cookies. Continuing to use 9bis.net means you agree to our use of cookies.
 

 

expr ( en )

Last modification : 2013/01/26 19:16

expr is the standard way to evaluate arithmetic expressions.
expr can recognize the 4 main operators (+, -, *, /) and % (the mod operator that return the reminder of the division of two integer), and power operator .

As it is in KSH the syntax is very strict. first, if you only need to print the result of an operation just write it like that:
msh> expr 1 + 3
4

Important notice: you must not forget the spaces between the operator and the operands.

If you need to make operations on variables you have to use the ((...)) syntax:
msh> set i=1
msh> (( i = $i + 1 ))
msh> print $i
2


Since there are so few operators, it is possible to switch to an enhanced arithmetic expressions evaluator: bc.
  • start directly MSH.EXE in bc mode:
msh.exe -bc

  • into interactive mode switch between expr and bc mode with internal command msh:calc
msh> msh:calc
(( ... )) now evaluated with bc
msh> msh:calc
(( ... )) now evaluated with expr (caution to the syntax)