6.5 Shell Arithmetic calculation

Source: Internet
Author: User
Tags arithmetic

6.5 Shell Arithmetic

The shell allows expressions to be evaluated inside, and can be used in the following ways: (Medium, let, and the declare command with the-i option.)

Only fixed-length integers are computed, and overflow is not checked, except that 0 can be captured and marked as error. Operators, precedence, associativity, and their values are exactly the same as in the C language. The following operators are grouped by priority, with precedence sorted from first to highest:

id++ id--   变量后+1,和后-1

++id --id  变量先+1,和先-1

-+    unary minus and plus sign

! ~       逻辑非,按位非

**        幂

* / %      乘号,除号,求余数

+ -        加号,减号

<< >>      左移位,右移位

<= >= < >    比较

== !=      相等,不等

&         按位与

^         按位异或

|        按位或

&&       逻辑与

||       逻辑或

expr ? expr : expr  Conditional operator

= *= /= %= += -= <<= >>= &= ^= |=  赋值

expr1 , expr2  逗号表达式

6.5 Shell Arithmetic calculation

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.