Easy Tutorial
❮ Linux Comm Pwd Linux Comm Ytalk ❯

Linux expr Command

Linux Command Manual

The expr command is a manual command-line counter used to evaluate the value of expression variables in UNIX/LINUX, typically for integer values, but it can also be used for strings.

Syntax

expr expression

Expression Instructions:

Examples

  1. Calculate string length

    > expr length "this is a test"
    14
    
  2. Extract substring

    > expr substr "this is a test" 3 5
    is is
    
  3. Find the position of the first occurrence of a character in a string

    > expr index "sarasara" a
    2
    
  4. Integer operations

    > expr 14 % 9
    5
    > expr 10 + 10
    20
    > expr 1000 + 900
    1900
    > expr 30 / 3 / 2
    5
    > expr 30 \* 3 (Use a backslash to mask the special meaning of the asterisk, as the shell might misinterpret the asterisk)
    90
    > expr 30 * 3
    expr: Syntax error
    

Linux Command Manual

❮ Linux Comm Pwd Linux Comm Ytalk ❯