Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   expr.1p    ( 1 )

оценивать аргументы как выражение (evaluate arguments as an expression)

Примеры (Examples)

The following command:

a=$(expr "$a" + 1)

adds 1 to the variable a.

The following command, for "$a" equal to either /usr/abc/file or just file:

expr $a : '.*/\(.*\)' \| $a

returns the last segment of a pathname (that is, file). Applications should avoid the character '/' used alone as an argument; expr may interpret it as the division operator.

The following command:

expr "//$a" : '.*/\(.*\)'

is a better representation of the previous example. The addition of the "//" characters eliminates any ambiguity about the division operator and simplifies the whole expression. Also note that pathnames may contain characters contained in the IFS variable and should be quoted to avoid having "$a" expand into multiple arguments.

The following command:

expr "X$VAR" : '.*' - 1

returns the number of characters in VAR.