qua*_*ote 78 linux bash shell command-line
如果您在 bash 中设置或导出环境变量,则可以取消设置。如果您在 bash 中设置了别名,则可以取消别名。但似乎没有unfunction。
考虑这个(简单的)bash 函数,例如,在.bash_aliases文件中设置并在 shell 初始化时读取。
function foo () { echo "bar" ; }
Run Code Online (Sandbox Code Playgroud)
如何从当前 shell 中清除此函数定义?
(更改初始化文件或重新启动 shell 不算在内。)
Chr*_*sen 106
在未设置的内置命令采用一个选项,-f以删除功能:
unset -f foo
Run Code Online (Sandbox Code Playgroud)
在bash联机帮助页中形成unset条目:
如果指定了 -f,则每个名称都引用一个 shell 函数,并删除函数定义。
注意:-f只有存在同名变量时才真正需要。如果您还没有一个名为 的变量foo,unset foo则将删除该函数。
见help unset:
unset: unset [-f] [-v] [-n] [name ...]
Unset values and attributes of shell variables and functions.
For each NAME, remove the corresponding variable or function.
Options:
-f treat each NAME as a shell function
-v treat each NAME as a shell variable
-n treat each NAME as a name reference and unset the variable itself
rather than the variable it references
Without options, unset first tries to unset a variable, and if that fails,
tries to unset a function.
Some variables cannot be unset; also see `readonly'.
Exit Status:
Returns success unless an invalid option is given or a NAME is read-only.
Run Code Online (Sandbox Code Playgroud)
既没有unset --help也没有man unset不幸。
| 归档时间: |
|
| 查看次数: |
23405 次 |
| 最近记录: |