Math using expr

suggest change

expr or Evaluate expressions evaluates an expression and writes the result on standard output

Basic arithmetics

expr 2 + 3

When multiplying, you need to escape the \* sign

expr 2 \* 3

You can also use variables

expr $a + 3

Keep in mind that it only supports integers, so expression like this

expr 3.0 / 2

will throw an error expr: not a decimal number: '3.0'.

It supports regular expression to match patterns

expr 'Hello World' : 'Hell\(.*\)rld'
o Wo

Or find the index of the first char in the search string

This will throw expr: syntax error on Mac OS X, because it uses BSD expr which does not have the index command, while expr on Linux is generally GNU expr
expr index hello l

expr index 'hello' 'lo'

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents