Linux commands: Let

Source: Internet
Author: User

The Let usage of Linux

1. Shell String Connection operation

[Email protected] sysroot]# var=1; var= $var +1;echo $var
Up


2, in the shell can use let to indicate that the following is an arithmetic expression, let expression inside the variable can not add $

[Email protected] sysroot]# var=3; Let "var=$var+1"; Echo $var
4
[Email protected] sysroot]# var=4; Let "Var=var+1"; Echo $var
5

[Email protected] sysroot]# var=5; Let "var+=1"; Echo $var
6 #Let must be a complete arithmetic expression that has both sides of the equals sign


3, the Let can be replaced by (()),Let″j=i*6+2″ equivalent to ((j=i*6+2)), like many of the cycle of the use of the same

[Email protected] sysroot]# var=7;  ((var++)); Echo $var

8

[Email protected] sysroot]# var=8; var=$[$var +1]; Echo $var
9

[Email protected] sysroot]# var=9; var= ' expr $var +1'; echo $var # plus no spaces next to string connections
9+1 # ' is not a single quote, is a command substitution, the key to the left of "1"


[Email protected] sysroot]# var=9; var=' expr $var + 1'; echo $var # plus no spaces next to arithmetic operations

10

[Email protected] sysroot]# var=9; Var=$ (expr $var + 1); echo $var # in the shell $ () and ' equivalent
10

[Email protected] sysroot]# var=9;  Var=$ (( $var + 1)); Echo $var
10

[Email protected] sysroot]# var=9; Echo $ (( $var + 1))
10


# (()), expr can be evaluated only to the right of the equals sign, by $ ((...)), $ (expr ...), ' expr ... ' to view the returned results


4. Processing floating-point BC

[Email protected] sysroot]# var=20; Var= ' echo ' scale=1; $var *3.5 "|  BC '; Echo $var
70.0


5. The method that supports floating-point arithmetic is awk

[Email protected] sysroot]# var=30; Var= ' echo ' $var 3 | awk ' {printf ("%g", $1+$2)} "; Echo $var
33

[[email protected] sysroot]# c=$ (awk ' begin{print 11.111*5-0.4} '); Echo $c
55.155


1: In the shell $ () is equivalent to '. Executes the command statement contained in the middle, returning the execution result.
2: From Efficiency let== (()) > expr > BC. Let and (()) run are built-in commands that use the same algorithm.
The operations of 3:let and expr are integer operations and do not include floating-point budgeting.
4:expr and BC are external programs, and the volume of expr is almost equal to 1/3 of BC, and less time is spent executing a load of memory at once.
5: From the computing power, BC ranked first.


---end---

Linux commands: Let

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.