expr - evaluate expressions


To add two numbers
$ expr 11 + 5

To subtract two numbers
$ expr 20 - 10

To divide two numbers
$ expr 20 / 4

To divide two numbers and want to see the remainder
$ expr 25 % 6

To multiply two numbers
$ expr 6 \* 4

To find the length of a string
$ expr length indianlinuxusergroupchennai

To check the index of character x
$ a=kanchilinuxusergroup
$ b=`expr index $a x`
$ echo $b

To extract the substring
$ a=indianlinuxusergroupchennai
$ b=`expr substr $a 21 27`
$ echo $b

To get the index of a substring from a string
$ expr substr indianlinuxusergroupchennai 21 27

To compare two expressions
$ a=50
$ b=60
$ c=`expr $a = $b`
$ echo $c

To match the number of characters of two string
$ expr linuxos : linux
$ expr linuxos : linuxo



regards,
T.Dhanasekar