Dynamic language: Interpreted language, is a weak type of language, Characteristics: Edge interpretation edge execution. Example: PHP, SHELL, Python, Perl
Weak: variable time declaration, or even type-insensitive.
Strong: Variables must be declared beforehand and even initialized before they can be used.
BASH: itself is a software, script interpreter.
Shell scripts are process-oriented.
Bash Variable type:
Environment variables
Local variables (local variables)
Positional variables
Special variables
Local variables:
Varname=value; scope: The entire bash process
Local variables
Local varname=value; scope: For the current code snippet
Environment variable: scope is the current shell process and its child processes;
①export Varname=value
②varname=value
Export VARNAME
Positional variables:
$1,$2,...
Special variables:
$7: The execution status return value of the previous command
program execution, there may be two types of return values:
Program execution Results
Program Status return codes (0-255)
0: Correct execution
1-255: Error execution 1,2,127 system reservation
echo $? View the status of the previous command execution
Reference variable: $ (VARNAME), parentheses can sometimes be omitted
When the script executes, it starts a child shell process, and the script that is started on the command line inherits the current shell environment variable, and the system automatically executes the script (not the command line startup) that requires a self-defined environment variable
Output redirection:
> Overwrite redirects
>> Chasing heavier orientation
2> Error Redirection
2>> Error Append redirect
&> simultaneous redirection
Undo Variable: unset VARNAME undo environment variable, local variable
View variables in the current shell: including environment variables, local variables
Set
To view environment variables in the current shell:
Printenv
Env
Export
Add something new to a variable:
Name=xiao
Name= $NAME:/liu after filling
Name=tian: $NAME Pre-fill
Note: All shell variables are strings and cannot be used for arithmetic operations
Script: Command stack, according to the actual needs, combined with the command flow control mechanism to implement the source program
First script:
The first line must be written at the beginning of the script:
#! /bin/bash
#注释行, do not perform
The script written in general does not have permission to execute: chmod +x filename
However, there are two ways of doing this:
① the path name of the file under path path
The ② is executed only under the current path./filename
Remove execution permissions: chmod-x filename
Specify bash interpreter to execute bash filename
Shell Programming Overview and variables