BASH built-in Variables
(1). BASH
Function: complete bash path. The default value is/bin/bash.
(2). BASH_ENV
Purpose: applicable only in non-interactive mode. When executing a shell script, the system first checks whether the variable has been specified to start
Script. If it is specified, run the specified STARTUP script first.
(3). BASH_VERSION
Role: bash version number
Instance: echo $ BASH_VERSION
(4). CDPATH
Function: the cd search path. Multiple paths are separated ':'.
Instance: CDPATH = "/tmp/A/B:/var/log"
(Assume the current directory is/home/example)
Mkdir-p/tmp/A/B/C
Cd C # by default, cd first searches for whether the C directory exists in the current directory. If it does not exist, it searches for the path specified by the CDPATH variable and enters/tmp/A/B/C.
(5). EUID
Role: valid user UID.
(6). FUNCNAME
Purpose: During function execution, the variable value is the function name.
Instance:
Hello ()
{
Echo "this function is named $ FUNCNAME"
}
Hello # The result is displayed as "this function is named hello"
(7). HISTFILE
Purpose: Specify the path of the historical script file, usually ~ /. Bash_history
(8). HISTFILESIZE
Purpose: set the maximum number of commands for storing historical files.
(9). HISTIGNORE
Purpose: Specify the sequence of commands not stored in the History script file. Multiple commands are separated ':'.
Instance: HISTIGNORE = ls: ps: cd: t *:\&
Note: commands not stored in history scripts are ls, ps, cd, and commands starting with t, and background commands (\&)
(10). HOME
Purpose: set the user's home directory to replace ~ Value
(11). HOSTNAME
Purpose: set the host name.
(12). HOSTTYPE
Purpose: set the host type.
(13). IFS
Purpose: Define the field separator. The default value is blank space (space, tab, line feed)
Instance:
MY = "1: 2: 3: 4: 5"
IFS =:
For I in $ MY; do
Echo $ I
Done
Result:
1
2
3
4
5
(14). INPUTRC
Purpose: set the startup configuration file of the command line function or readline library to overwrite ~ /. Inputrc settings
(15). LANG
Purpose: Set the name of the current language family.
(16). LC_ALL
Purpose: set the current locale to overwrite the LANG and LC _ * settings.
(17). LC_CTYPE
Purpose: set the character category of locale.
(18). MACHTYPE
Role: the GNU format that describes the host format: CPU-company-System
Instance: echo $ MACHTYPE # i686-pc-linux-gnu
(19). OLDPATH
Role: previous working directory
Instance: cd-equivalent cd $ OLDPATH
(20). PATH
Purpose: set the search path for external commands, separated ':'.
(21). PPID
Role: PID of the parent process
(22). PS1 (this is number 1)
Purpose: set the main prompt symbol. The default value is \ s-\ v \ $.
(23). PS2
Purpose: set the secondary indicator. The default value is>
(24). PS3
Purpose: set the select prompt. The default value is #?
(25). PWD
Role: current working directory
Instance: echo $ PWD equivalent pwd
(26). SECONDS
Purpose: display the startup time of the Current shell (unit: s)
Instance: echo $ SECONDS
(27). SHELL
Purpose: The currently used shell name. The default value is/bin/bash.
(28). TMOUT
Purpose: if the value of this variable is greater than 0, bash will automatically end the current bash shell after waiting for TMOUT seconds without any operation.
Instance:
Echo 'tmout = 100'>/etc/profile # If no operation is performed within 10 minutes, the system is automatically logged out.
(29). UID
Role: User ID
(30). $1, $2,..., $ N
Role: Location Parameter. $ {N} is used to represent the parameter when it exceeds 9.
(31). $
Role: current process number
Instance: echo $
(32). $?
Purpose: The exit status of the previous command.
Instance: echo $?
Note: This variable is generally used to determine whether the previous command is correctly executed. Generally, when the value is 0, it indicates that the previous command is correctly executed; otherwise, it is not correctly executed.
(33). $ #
Role: Number of location parameters
(34). $!
Role: ID of the process that runs the program in the previous background.
Instance: top & # assume its PID is 2112
Echo $! # Result 2112
Author: "huangyandong"