8, linux-Digital calculation

Source: Internet
Author: User
Tags arithmetic

Tag: Seq Font calculates the specified interaction of the comment line nts file

Bash has built-in support for integer arithmetic, but it does not support floating-point arithmetic

The BC command is a calculator language that supports interactive execution of arbitrary precision, while the BC Command makes it easy to do floating-point operations , and of course integer arithmetic is no longer spoken

In the BC working environment, you can use the following calculation symbols:
+ Addition
-Subtraction
* Multiplication
/Division
^ Index
% remainder

Seq 10;seq 1 10;seq 1 1 10

Cat << seq >> 123

Where you can use scale to Specify the number of digits after the decimal point when doing a "divide calculation" or "Remainder calculation" (the default is 0, which is an integer)

1. Bash

Example 1:a=2;b=3 echo $ (($a + $b)) #结果为5

2, BC quit

Examples 2:a=2;b=3 BC <<< 2*3(or BC <<< $a * $b) #结果为6

Example 3: BC enters interactive mode calculation: You can also enter multiple calculations on one line, with commas ; Apart

Example 4: You can also calculate the results directly without interacting echo "(6+3) * * |BC echo 15/4 |bc echo" SCALE=2;15/4 "|BC echo" 3+4;5*2;5^2;18/4 "|BC Echo $a + $b |BC  

Example 5:BC can pick up the file name after

Cat Calc.txt

  20+89   56-17   34*45BC Calc.txt   109   39   1530Example 6: You can also use the here command bc << HERE > 30+56 > 30-14 > 30*5 Here 86 16 1503, Awkawk in the processing of files, you can perform operations, which of course can also be used to calculate the awk ' begin{a= (3+2) *2;printa} ' awk ' begin{a= (3+2) * *;b= (5+8) *10/5;printA, b} ' awk ' Begin{a= (3+2) *2;b= (5+8) *10/5;print2a,3b}‘

8, linux-Digital calculation

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.