Shell Programming Details (i)

Source: Internet
Author: User
Tags arithmetic

Shell programming

The language is divided into:

Compiled languages: first to be translated into executable format

Interpreted language: Side interpretation side Execution


Variables: The shell is a weakly typed programming language, and the variable does not need to indicate the type and initialization, but the context determines the type

Bash Variable type:

Environment variables

Local variables

Positional variables

Special Custom variables


Local variables: scope for the entire bash process

Varname=value

Local variables: Scope current Code

Local Varname=value

Environment variable: scope is the current shell process and child process

Export Varname=value


Conditional judgment

How to achieve conditional judgment in hash?

Condition Test Type:

Integer test

Character test

File test


Expressions for Conditional tests:

[Expression]

[[Expression]]

Test expression


Integer comparison:

-EQ: Tests whether two integers are equal

-ne: Not Equal

-GT: Greater Than

-LT: Less than

-ge: greater than or equal to

-le: Less than or equal to


Logical relationships between commands:

Logic and:&&

Logical OR: | |

Logical non-:!


Condition Judgment: Control structure

if judgment condition; Then

Statements

Elif judgment condition; Then

Statements

Else

Statements

Fi


How to perform arithmetic operations in the shell:

A=3

B=6

Let arithmetic op-expression

Let c= $a + $b

$[arithmetic Operation expression "

c=$[$a + $b]

$ ((arithmetic operation expression))

c==$ (($a + $b))

Expr arithmetic expression, with spaces between operands and operators in an expression, and using command references

C= ' expr $a + $b '


This article is from the "Forget the Past" blog, please be sure to keep this source http://xujingbo.blog.51cto.com/4633099/1826526

Shell Programming Details (i)

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.