Seven. Shell script programming

Source: Internet
Author: User
Tags arithmetic

Shell login mode, shell arithmetic operation, Shell logic operation, shell condition test, Shell selection statement

Shell programming in the first line indicates the path of the shell type to be executed

e.g #/bin/bash

1. Shell Login Method

Interactive login:/etc/profile--/etc/profile.d/*.sh--/~/.bahsh_profile--~/.BASHRC--/ETC/BASHRC

Non-interactive login: ~/.BASHRC--/ETC/BASHRC--/etc/profile.d/*.sh

2. Shell arithmetic operations

(1) Operation symbol:

+ Add

-Sub

* Mul

/div

% remainder

(2) Four ways to implement arithmetic operations

A. Let varname=expression

Let varname=2+3, let varname=2*3

B. varname=$[expression]

VARNAME=$[5*6]

C. varname=$ ((expression))

varname=$ ((2+3))

D. varname=$ (expr arg1 arg2 arg3 ...)

varname=$ (expr 2 + 3)

3. Logical operation

&& Logical AND

|| Logical OR

! Logical not

4. Condition Testing

Determines whether an expression is true, completed by a test statement

Test command

Test EXPRESSION

[EXPRESSION]

[[EXPRESSION]]

Test comparison symbols

Numerical

-GT great than

-lt less than

-eq equal

-ne Not Equal

-ge great than or equal

-le less than or equal

e.g Test 2-eq 2, [4-ge 3]

String

= = Strings is equal

> Strings is great

< strings is less

! = strings is not equal

-Z "string": test whether the string is empty, the vacancy is true

-N "string": test whether the string is not empty, not empty is true

File test

TEST-E file test files are present

5. SELECT statement

If-then

If COMMAND

Then

COMMAND

If-then-else

If COMMAND

Then

COMMAND

If-then-elif-then-else

If COMMAND

Then

COMMAND

Elif

Then

COMMAND

...

Else

COMAND

Seven. Shell script 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.