5
Contributors
6
Replies
7
Views
9 Years
Discussion Span
Last Post by masijade
0

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.

0

Dear ,

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 ???????????


sanjay

0

Dear friends ,

i solved this problem by following ..........


echo `expr 2 + 4`

its give result 6 .we should give space between operator and operand


sanjay

0

With bash if you are typing on the command line you can just type

$ expr 2 + 4
6

If you are putting it in a file, you can do

#! /bin/bash

expr 2 + 4
var=`expr 2 + 4`
echo $var


and it will print:
6
6

0

If you're using a more advanced shell than posix or sh, you can use "let" also - just a suggestion :)

let var=2+4
echo $var

let works the opposite of expr, in so far as the spaces go - you shouldn't put any spaces between operators and operand

, Mike

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.