Advanced Features of If-then
[[]], [] are used to test (test is divided into numeric comparisons, string comparisons, file parity),[[]] is a keyword , which can be used &&, | |, <, > and other similar C language syntax ; [] is a command that is embedded in bash and is used for testing. [[]] versatility is better.
(()), similar to let, used to evaluate an expression . () You can enclose multiple commands and run them in a child shell.
Summary of Usage methods:
Involves advanced mathematical operations using (())
Execution using () involving multiple commands
Involves advanced syntax testing using [[]]
Commands that involve bash embedding []
1. Double angle brackets for mathematical expressions
(expression) allows advanced mathematical expressions to be put into comparisons. The test command only allows simple arithmetic operations in the comparison.
Expression can be any mathematical assignment or comparison expression. In addition to the standard mathematical operators used by the test command, the double-angle bracket command symbol also has:
val++ val--++val--val! ~ * * << >> & | && | |
Double angle brackets are used in normal commands as assignment functions.
((Val2 = $val 1 * * 2))
2. Two-side brackets for advanced string processing functions
The comparison is made using the standard string used in the test command. However, it provides a pattern-matching feature that is not provided by the test command. You can define a regular expression to match a string value. Such as:
if [[$USER = = r*]]
Notes on Linux shell programming