Bash Variable type:
Environment variables
Local variables (local variables)
Positional variables
Special variables
Local variable: Valid only in the current process (shell).
BASH: Direct use, no need to declare: Name = Jerry;
Variable substitution: How to reference a variable: ${variable}. Curly braces can be omitted most of the time, as in the above example, to use the values in a variable, echo$name.
Exception: double quotation marks (if referenced): for example, Name = pig, want to output there is some pigs need to write:
echo "There is some ${pig}s"
Single quotation mark (strong reference): in single quotes, even using ${pig},bash still does not use the data in the variable, but directly output ${pig}, the variable as a string.
Local variable scope: Entire bash process
Local variables: Local, valid only for the current code snippet
Environment variable: scope is the current shell process and its child processes
Export Varname=value
Positional variables: $1,$2, referencing script parameters
Special variables:
General program execution has two types of return values: execution result and execution state
$?: Saves the execution status return value of the previous command. Success for: 0, others for failure
Status: 1, 2,127: Command error. System reservation.
Output redirection:
> Overwrite redirects
>> Chasing heavier orientation
2> Error Overwrite redirect
2>> Error Append redirect
&> simultaneous redirection
Output redirection has a special location in the/dev/null: bit bucket. The data black hole can output any information inside.
ID student &>/dev/null The result of the command, regardless of the result of the failure or success, to the output here.
Undo variable: unset variable name
View variables: Set without any parameters
View current Environment variables: env or export
This article is from the Linux learning blog, so be sure to keep this source http://884482.blog.51cto.com/874482/1695821
One of the Bash shell basics