1

Using expr to evaluate an expression in bash, the following happened

bash-3.2$ expr 1+1
1+1
bash-3.2$ expr 1 + 1
2

Why should the plus sign be padded by space for it to be interpreted as mathematical operation?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
mc9
  • 6,121
  • 13
  • 49
  • 87

1 Answers1

4

I suspect this has little to do with bash. From the man page of expr :

All operators and operands must be passed as separate arguments

In order for operands and operators to be interpreted as separate arguments, You have to separate them (with a space).

francesco foresti
  • 2,004
  • 20
  • 24