The variables in Linux are divided into
Local variables, environment variables, local variables, positional variables, special variables
Local variables: Valid for the current shell process only, effective immediately
Usage: variable name = value
Reference: ${variable name}, greater than number can be omitted
Cases
[Email protected] ~]# Name=jerry[[email protected] ~]# echo $namejerry
Environment variables:
1. Valid for all child shells of the current shell and current shell, effective immediately, logout is invalid
Usage: Export Variable name = value
Cancel: unset variable name
Cases
[[email protected] ~]# export Name=andy[[email protected] ~]# bash[[email protected] ~]# echo $nameandy [[email protected] ~]# Exitexit
2, valid for all shells, write to file, command load or re-login takes effect
File All directories: Interactive/etc/profile,/etc/profile.d/*.sh or ~/.bash_profile, non-interactive/ETC/BASHRC, ~/.BASHRC
After writing, use: . File name or source file name to import, or you can log in again
There are many environment variables in bash, which are usually denoted by the command: Set,export, printenv,env to query
The following is a sequence of configuration file access for both interactive and non-interactive logon types
Interactive:/etc/profile-->/etc/profile.d/*.sh-->~/.bash_profile-->~/.bashrc--> ETC/BASHRC
Non-interactive: ~/.bashrc-->/etc/bashrc--> etc/profile.d/*.sh
Local variables
Variables in a function
Position variable: The first parameter that represents a reference
$, $2...${10} double-digit to use greater than sign
Special variables
$?: Execution status of last command 0 indicates success, greater than 1 means unsuccessful and corresponding error code
$#: Number of parameters
$* or [email protected]: all parameters
Variables in Linux