What is the `expr` command?

0160

The expr command is a Unix/Linux utility used for evaluating expressions and performing basic arithmetic operations in the terminal. It can handle integer arithmetic, string operations, and logical comparisons.

Basic Usage:

  • Arithmetic Operations: You can perform addition, subtraction, multiplication, and division.
  • Syntax: The general syntax is:
    expr <expression>

Examples:

  1. Addition:

    expr 5 + 3  # Outputs: 8
  2. Subtraction:

    expr 10 - 4  # Outputs: 6
  3. Multiplication:

    expr 6 \* 7  # Outputs: 42 (note the backslash before *)
  4. Division:

    expr 20 / 4  # Outputs: 5

Important Notes:

  • Ensure there are spaces around operators.
  • For multiplication, use a backslash (\) before the asterisk (*) to avoid shell interpretation.

If you have more questions about expr or need examples, let me know!

0 Comments

no data
Be the first to share your comment!