Linux command
unset 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Unset variable
unset [VARIABLE]
Unset function
unset -f [function_name]
Unset multiple variables
unset [VAR1] [VAR2]
Unset variable explicitly (not function)
unset -v [VARIABLE]
说明
unset is a shell builtin that removes variables and function definitions from the current shell environment. By default it removes variables, but with the -f flag it removes function definitions instead. Unsetting a variable removes it completely from the environment, unlike setting it to an empty string which leaves the variable defined but empty. This distinction matters for scripts that check whether a variable exists versus whether it has a value. Unsetting exported variables also removes them from the environment inherited by child processes. Changes made by unset only affect the current shell session. Variables and functions defined in shell startup files like ~/.bashrc will be restored when a new shell session starts. Read-only variables cannot be unset.
参数
- -f
- Unset function.
- -v
- Unset variable (default).
- -n
- Unset the nameref variable itself rather than the variable it references.
FAQ
What is the unset command used for?
unset is a shell builtin that removes variables and function definitions from the current shell environment. By default it removes variables, but with the -f flag it removes function definitions instead. Unsetting a variable removes it completely from the environment, unlike setting it to an empty string which leaves the variable defined but empty. This distinction matters for scripts that check whether a variable exists versus whether it has a value. Unsetting exported variables also removes them from the environment inherited by child processes. Changes made by unset only affect the current shell session. Variables and functions defined in shell startup files like ~/.bashrc will be restored when a new shell session starts. Read-only variables cannot be unset.
How do I run a basic unset example?
Run `unset [VARIABLE]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -f do in unset?
Unset function.