How to use the Linux expr command

Source: Internet
Author: User

It is used to evaluate the value of expression variables in UNIX/LINUX. It is generally used as an integer or a string.

Syntax

Expr expression

Expression description:

  • Separate each item with spaces;
  • Place the slash (/) before a specific shell character;
  • Enclose strings containing spaces and other special characters in quotation marks.

Instance

1. Calculate the string length

> Expr length "this is a test"

14

2. Capture strings

> Expr substr "this is a test" 3 5

Is

3. Capture the position where the first character numeric string appears

> Expr index "sarasara"

2

4. Integer operation

> Expr 14% 9

5

> Expr 10 + 10

20

> Expr 1000 + 900

1900

> Expr 30/3/2

5

> Expr 30/* 3 (when using a multiplication number, you must use a backslash to block its specific meaning. Because shell may misunderstand the meaning of the asterisk)

90

> Expr 30*3

Expr: Syntax error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.