Methods for variable auto-increment in Linuxshell (or calculation)

Source: Internet
Author: User
Tags echo b
Several methods (or calculation operations) for variable auto-increment in Linuxshell-Linux general technology-Linux technology and application information. For more information, see the following. I remember the section about the Linux shell loop that involved variable auto-increment (integer arithmetic operation). I think it is easy to make a mistake. Now I will summarize several common methods:
1. Use expr
# Expr 10 + 10 ==> 20
# A = 'expr 10% 3'; echo $ a ==> 1
# B = 10; B = 'expr $ B + 1' => 11 (implement variable auto-increment 1)
2. Use $ []
# Echo $[10 + 10] ==> 20
# A = $ [10% 1]; echo a => 1
# B = 10; B = $ [$ B + 1]; echo B => 11 (implement variable auto-increment 1)

The auto-increment operation of variables can also be implemented as follows:
# C = 100
# Let c + = 1 ==> 101

If it is helpful to you, please reply to the support! Thank you.
: 0) 1

[ This post was last edited by lyq617617]
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.