Shell Simple usage note (Shell numeric operations) two

Source: Internet
Author: User

The value of the variable in the shell, if you do not specify the type manually, the default is the string type:

For example:

A=123b=456C= $a +#becho $c

The result is output: 123+456

In the shell, if you want to perform numeric operations, you can do this by:

Method 1:

A=123b=456C=$ (($a + $b))

Method 2:

A=123b=456declare-i C= $a + $b

The value type of C is declared by Declare-i to be of type int

Method 3:

A=123b=456C=$ (expr $a + $b) Note that there are spaces on both sides of the + sign

Add and subtract strings by using the Marten expr command

Shell Simple usage note (Shell numeric operations) two

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.