[Boiled water]-shell-from numerical N to M (n<m)-Knowledge point

Source: Internet
Author: User

Title: Numerical N accumulates to M (n<m)

In the following example, the examples are 1 to 100, and they can be brought into N and M (n<m) entirely by themselves.

For loop implementation
Sum=0for ((i=1;i<=100;i++)) do sum=$ ((i+ $sum)) Doneecho $sum


By using variable arithmetic to implement
Echo $[$ (Echo +{1..100})]echo $ (($ (Echo +{1..100})) echo $[(100+1) * (100/2)]
Knowledge Points:
I=2&&echo $ ((i+3)) # Prints new variable results after calculation I=2&&echo $[i+3]# calculation of new variable results


$ (()) and $[] As a result, the two variables are expressed in different forms, but the results are the same

Implemented with SEQ and BC commands
Seq-s ' + ' |BC
Knowledge Points:
Seq Common parameter # does not specify the starting value, the default is 1-s # option mainly change the output of the splitter, the preset is \n-w # equal complement, that is, the width equals, insufficient front fill 0-f # formatted output, is the format of the specified printing



Thank:

Learn how to loosely summarize Linux

Old boy teacher's blog share

[Boiled water]-shell-from numerical N to M (n<m)-Knowledge point

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.