What shell are you using. If it is bash or csh or somesuch, you need to use backquotes:
echo `expr 2+4` Hope this helps.
I am using Bash shell and i did echo `expr 2+4`
but it give 2+4 not 6 ..
plz help me sir why its not working ???????????
Dear friends ,
i solved this problem by following ..........
echo `expr 2 + 4`
its give result 6 .we should give space between operator and operand
With bash if you are typing on the command line you can just type
$ expr 2 + 4
If you are putting it in a file, you can do
expr 2 + 4
var=`expr 2 + 4`
and it will print:
If you're using a more advanced shell than posix or sh, you can use "let" also - just a suggestion :)
let works the opposite of expr, in so far as the spaces go - you shouldn't put any spaces between operators and operand
You can also, as long as it is not csh or sh, just simply do
var=$(( 2 + 4 ));
var=$(( $var + 2 ));