Why should arithmetic operators be padded by space in expr?

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?

1 answer

  • answered 2018-01-14 22:05 francesco foresti

    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).