Shell Scripting App (shell scripting Basics vs. Shell variables)

Source: Internet
Author: User

1. Shell: Command interpreter
1) supported shells are saved in/etc/shells

2) Default shell is/bin/bash

2. Shell script writing:

1) using the VI Editor

2) One command per line, followed by

3) Give executable permissions (x)

3, the way of implementation:

1) script file path: There are two, relative and absolute paths that must have X permissions

2) SH script file path: No x permission, relative and absolute path can be, on the child shell

3) Source (or.) script file path: Do not need x permission to execute at current sell

4. Script Composition:

1) Script declaration: Specifies the shell that the script executes to #! Beginning

2) Comment Information: explanatory text, beginning with #, does not execute

3) executable statement:

5. Input and output redirection and pipe characters

Input device: File name/dev/stdin number 0 for keyboard

Output device: File name/dev/stdout number 1 corresponds to the display

Error Output: File name/dev/stderr number 2 corresponds to display

: Output redirected to file, create or overwrite original file

<: Input Redirect to file

Append output Redirect to file

2>: Error message output redirected to file

&>: Mixed output redirected to the same file

|: Pipe character, give left command result to right command execution

awk command: Outputs the specified range of information with the specified character as a delimiter, and the default delimiter is a space

Awk-f: ' {print $1,$7} '

6. Variable classification:

1) Custom variables: User-defined

2) Environment variables: Automatic system creation

3) Position variable: Command parameter location: $1~$9

4) Pre-defined variables: variables with fixed meanings

7. Custom variables:

1) Define a variable: variable name = variable value proposed all uppercase (case-sensitive)

2) View variable value: Echo $ variable Name example: Echo $A [plus $ display value, no display name (A)]

3) The effect of quotation marks on variables:

(1) Double quotation marks: The value of the reference variable

(2) Single quote: Show variable name

(3) Anti-apostrophe: EXECUTE AS command, get command result, do not allow nesting, Can $ () instead

(4) Assigning values to variables from keyboard input:

READ-P "hint Information" variable name

(5) Publish variable: Export variable name "= Variable Value" Child shell also valid

(6) Integer operation: Expr variable 1 operator variable 2 (example: EXPR3 * 4)

Operator: Plus (+) minus (-) multiply (*) divide (/) remainder (%)

8. Environment variables:

Configuration file:

1) Global: Effective/etc/profile for all users

2) User: Valid only for users ~/.bash_profile

Common environment variables:

1) PWD: Current working directory

2) Path: Paths for command search

3) User: Current user

4) Shell: Shell of the current user

5) HOME: The current user's host directory

6) Histsize: Record the number of history commands, default to 1000

7) UID: Current User ID

9. Position variable: The position of the command parameter, represented by $1~$9, first to Nineth

10. Pre-defined variables:

1) $#: The number of positional variables in the command line

2) $*: Contents of all positional variables

3) $?: Result of previous command execution, normal 0, non 0 value indicates exception or error

4) $ A: Represents the script itself

Other commands:

Date +%y Year

Date +%y-%m Month

Date +%y-%m-%d Month Day

Shell script Application (shell script base and shell variable)

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.