expr

expr command is used to perform shell arithmetic and evaluate expressions

Syntax/Usage

expr expression




		
Examples:- 	a=7
			b=10
			expr $a + $b      		 // output: 17
			c=`expr $a – 4`  		//result 3 is stored in variable ‘c’
			echo `expr $b % $a`	//remainder 3 is printed

		

Note: Notice space on either side of the ‘+’ operator .

	
		
expr in shell arithmetic
		
		Figure 1
		


Alternative Way of arithmetic expression


		
Examples:-
			c=$((a+b))
			c=`expr $a + $((b*b*b))`
			c=$((a+(b*b*b)))

		

Note:-