Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of Linux's let command

Shulou Source: shulou.com Published: 2022-06-01 18:45:48 10月05日 Update

This article mainly explains "what is the use of Linux's let command". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the use of Linux's let command"?

Let simple calculator that executes arithmetic expressions.

Summary let arg [arg...] The main purpose is to execute one or more arithmetic expressions.

Parameter arg: arithmetic expression

The return value returns 1 if the last expression executed by let evaluates to 0, otherwise 0. When the divisor of the expression executed by let is 0, 1 is returned and an error is reported.

Operator precedence decrement table operator describes id++, id-- variable increment, variable decrement + + id,-- id variable pre-increment, variable pre-decrement -, + positive sign, negative sign!, ~ logical No, inverse * * exponentiation *, /,% multiplication, division, remainder +,-addition, subtraction > move left by bit, move right =, compare = = ! = equal to or not equal to & bitwise and ^ bitwise XOR\ | bitwise or & & logic and\ | Logic or expr? Expr: expr conditional operator (ternary operator) =, * =, / =,% =, + =,-=, > =, & =, ^ =,\ | = assignment example # attempts to execute arithmetic expressions directly in the terminal (like IDLE in python). 3-4 bash:3+4:command not found... # another way. 3 + 4 bash:3:command not found... # it doesn't seem to work. # let command assignment. Let axioms 4 echo ${a} # shows 81. # (()) Is equivalent to the let command. ) # let is often used for variable assignment, while the external command expr can directly return the value of an expression. Let 3 # 4 # does not display 7. # displays 7 after execution, pay attention to the space. Expr 3 + 4 # conditional expression. If ((8 > 4)); then echo'8 is greater than 4.' Else echo 'error' fi # pay attention to the spaces. If [[12-le 10]]; then echo 'error' else echo' 12 is greater than 10.' Fi # can perform arithmetic operations by setting integer properties with the declare command. The # local command is similar. # No integer attribute specified, output as the string 'aroomb'. Declare axiom 3 bounded 4 c c=a+b echo ${c} # but you can assign values in the following ways. ((aqb)) echo ${c} # shows that 7 # can be added directly if the integer property is set. Declare-I axiom 3 bang 4 c c=a+b echo ${c} # Ibid. Declare-I a number 2, 3, echo ${a} # shows 6. Note that this command is a bash built-in command. For help, please see the help command.

In addition to let, there are external commands such as expr, bc, and so on.

At this point, I believe you have a deeper understanding of "what is the use of Linux's let command?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Commands expressions arithmetic operations variables operators attributes logic content increments methods methods conditions spaces learning no practical deeper multiplication priority Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Linux MariaDB vpn Docker