The expr command in the shell

Source: Internet
Author: User

Expr can do the following:

Logical operations

Arg1 | Arg2 logic or operation, true return arg1, otherwise return arg2 (null or to determine the true and false parameters, there is a short-circuit function)

Arg1 & arg2 Logic and operation, true return arg1, otherwise return arg2 (null or to determine the parameter is true, short circuit function)

Relational operations

Arg1 = Arg2 (or arg1 = = arg2) returns equal to 1, unequal return 0

Arg1! = arg2 returns 1, equal returns 0

Arg1 > Arg2 is greater than return 1, otherwise returns 0

Arg1 >= arg2 is greater than or equal to return 1, otherwise returns 0

Arg1 < arg2 less than return 1, otherwise return 0

Arg1 <= arg2 is less than or equal to return 1, otherwise returns 0

It is important to note that in a relational operation, only all parameters are numeric and are numerically compared, otherwise, by dictionary order

Arithmetic operations

Arg1 + arg2

Arg1-arg2

Arg1 * arg2

Arg1/arg2

Arg1% arg2

It is important to note that * There are other meanings in the shell, so you need to escape using \*

String manipulation

String:regexp

1) REGEXP represents a regular expression, and the expression implies ^, that is, REGXP is ^regexp;

2) If there is no \ (and \) in the regexp, then the number of matched characters is returned, or the total mismatch returns 0, and if \ (or \) is returned, the string containing the \ (and \) will return, or the mismatch returns null

Match STRING REGEXP

Class String:regexp Same

substr STRING POSITION LENGTH

Returns the substring from position (starting at 1), long length, if position and length are 0, negative, or non-negative, then returns null

Index STRING CHARSET

CharSet can contain more than one character, but only returns the position of the first character in string, and returns 0 if the characters in CharSet are not in string.

Length STRING

Returns the length of a string

+ TOKEN

The token is interpreted as a string, even if token is a keyword, such as expr index index n, because the second index is the keyword of the expr syntax, the error is handled as follows: Expr index + index n

All of the above expressions need to be aware that there must be spaces on both sides of the operator.

The expr command in the shell

Related Article

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.