Operation expression under the shell

Source: Internet
Author: User
Tags arithmetic operators

Commonly used arithmetic operators, assuming that variable A is 10 and variable B is 20:

Operator Description Example

+ addition ' expr $a + $b ' result is 30.

- subtraction ' expr $a-$b ' result is 10.

* multiply ' expr $a \* $b ' result is 200.

/ Division ' expr $b/$a ' result is 2.

% "expr $b% $a ' result is 0.

= Assignment a= $b assigns the value of variable B to a.

= = equal. Used to compare two numbers, the same returns true. [$a = = $b] returns FALSE.

! = is not equal. Used to compare two numbers, and returns true if they are different. [$a! = $b] Returns TRUE.

NOTE: Conditional expressions are placed between square brackets and have spaces, for example: [$a = = $b] is wrong and must be written as [$a = = $b].


Operation expression under 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.