expr

v0.0.14
expr [EXPRESSION]
expr [OPTIONS]

Print the value of EXPRESSION to standard output

Options

--version

output version information and exit

--help

display this help and exit

Examples

Get string length:

expr length {{string}}

Evaluate logical or math expression with an operator ('+', '-', '*', '&', '|', etc.). Special symbols should be escaped:

expr {{first_argument}} {{operator}} {{second_argument}}

Get position of the first character in 'string' that matches 'substring':

echo $(expr index {{string}} {{substring}})

Extract part of the string:

echo $(expr substr {{string}} {{position_to_start}} {{number_of_characters}}

Extract part of the string which matches a regular expression:

echo $(expr {{string}} : '\({{regular_expression}}\)')

The examples are provided by the tldr-pages project under the CC BY 4.0 License.

Please note that, as uutils is a work in progress, some examples might fail.