Notes on Linux shell programming

Source: Internet
Author: User

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

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.