Expr command in unix

Expr is a command line unix utility which evaluates an expression and outputs the corresponding value. Expr evaluates integer or string expressions, including pattern matching regular expressions. Most of the challenge posed in writing expressions is preventing the invoking command line shell from acting on characters intended for expr to process.

The syntax for the expr command is
                        expr [expression]                         

Arithmetic Operators Examples  
  • Sum of numbers
                 $ expr 2+3    
  • Multiplying two numbers
                $ expr 5 \*4              
  • Dividing two numbers   
                   $ expr 9/4                 

Relational Operators

  • Arg1< Arg2: Returns1, if Arg1 is less than Arg2. Otherwise zero
  • Arg1>Arg2: Returns1, if Arg1 is greter than Arg2. Otherwise zero
  • Arg1=Arg2: Returns1, if Arg1 is equl to Arg2. Otherwise zero
  • Arg1<=Arg2: Returns1, if Arg1 is less than or equl to Arg2. Otherwise zero
  • Arg1>=Arg2: Returns1, if Arg1 is greater than or equl to Arg2. Otherwise zero
  • Arg1|Arg2: Returns Arg1, if Arg1 is neither null nor zero. Otherwise Arg2
  • Arg1&Arg2: Returns Arg1 if both Arg1 & Arg2 is neither null nor zero. Otherwise zero
1.                               $ expr 3\ >7                       

2.                      $ expr  3=3                               

3.                         $ expr 4\<3                             

Powered by Blogger.