Linux Math Operations

Source: Internet
Author: User
Tags square root

    • Let command
A=1b=2letc=a+becho $c
View Code
Let a++b+ +echo $a $b
View Code
    • [] Method
A=1b=2echo $[a+b]echo $[$a + $b]
View Code
    • (()) method
A=1b=2echo $ ((a+b))
View Code
    • Expr method
A=1b=2C=$ (expr $a +$b)echo $c
View Code

Note: The above four methods are only for integer operations, if the floating-point operation to use the BC This advanced tool

[Email protected]:~$ num1=1.1[email protected]-pc:~$ num2=2.2[email protected]-pc:~$ num3= 'Echo "$num 1 * $num 2"|BC ' [email protected]-pc:~$Echo$num 32.4[email protected]-pc:~$ # Set decimal precision with scale parameter [email protected]-pc:~$ num3= 'Echo "scale=7, $num 1 * $num 2"|BC ' [email protected]-pc:~$Echo$num 32.42[email protected]-pc:~$ # using BC for carry-on conversion [email protected]-pc:~$ # decimal goto binary [email protected]-pc:~$ num=123[email protected]-pc:~$ result= 'Echo "obase=2; $num"|BC ' [email protected]-pc:~$Echo$result1111011[email protected]-pc:~$ # binary goto decimal [email protected]-pc:~$Echo "obase=10;ibase=2; $result"|BC123[email protected]-pc:~$ # uses BC to calculate square and square root [email protected]-pc:~$Echo "sqrt (+)"|BCTen[email protected]-pc:~$Echo "10^10"|BC10000000000[email protected]-pc:~$
View Code

Linux Math Operations

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.