1.shell command interpreter or shell auto-ops language
2. How to execute a shell script
(1) Execute permission must be given./first.sh
(2) SH first.sh
(3) Source first
3. More complete Script composition
Script Declaration
Comment Information
Executable statements
Example: vi/first.sh
#!/bin/bash
This is my first shell-script.
cd /boot echo "当前的目录位于:"pwd echo "其中以vml开头的文件包括:" ls -lh vml*
4. Standard input: stdin 0
Standard output: StdOut 1
Standard error: stderr 2
5. REDIRECT Operation
REDIRECT output: > or append >>
REDIRECT input: <
Standard error Output:2> or error append 2>>
Mixed output: &>
6. Variable: An element that holds a variable value
7. Common variables: Custom variables, environment variables, positional variables, pre-defined variables
(1) Custom variables: variables defined by the user according to their own environment
(2) environment variable: The environment variable refers to the system operation needs to be created by the Linux system in advance a class of variables, mainly for the user's working environment, including the user's host directory, the search path of the command, the user's current directory, login terminal, etc., the value of the environment variable has its own maintenance of the operating system itself, Changes as the user's state changes. environment variable configuration file/etc/profile.
(3) Positional variables: parameters are assigned to variables in the left and right order. $9
(4) Pre-defined variables
? $#: Number of positional variables in the command line (the program executes several positional parameters)
? $*: The contents of all positional variables (specific content such as/boot is a specific content)
? $?: The state returned after the previous command was executed, when the return status value is 0, the execution is normal, a value other than 0 indicates an exception or an error, or if an error is normal 0 exception error is not 0 value between 1-127
? $: The currently executing process/program name (which is the name of the currently executing command or program)
8. Variable specification:
Basic format: Variable name = variable Value (note: No spaces are allowed before and after "=")
Variable name: You can only start with a letter and underscore the name cannot contain special characters, try to use uppercase to determine the variable name
Double quotation mark "": Value is a long string or there is a space in the middle, can reference a variable
Single quote ': value cannot have special meaning characters, non-reference variable
Anti-apostrophe ': Assigns a command's screen output to a variable, equivalent to $ ()
Read command: Interactive assignment variable
9. View variables
Set view all current variables
ENV View global Variables
Basic knowledge of shell scripts