bash 删除函数定义(unalias 等价物)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6807188/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 00:25:47  来源:igfitidea点击:

Remove function definition (unalias equivalent)

bashshellzsh

提问by greg0ire

I'm currently building a program which adds to the current user's shell depending on the project he's working on, by defining per-project aliases and functions. These aliases and functions may and will certainly have the same name like for instance cdproj, which would cdto the project's root.

我目前正在构建一个程序,该程序通过定义每个项目的别名和函数,根据他正在处理的项目添加到当前用户的 shell。这些别名和函数可能并且肯定会具有相同的名称,例如cdprojcd对于项目的根目录。

I would like to remove previously defined aliases and functions when changing project (before (re)defining aliases and functions for the other project. I know I can remove an alias with unaliasin both bash and zsh, but how would I do the same for a function?

我想在更改项目时删除以前定义的别名和函数(在(重新)定义另一个项目的别名和函数之前。我知道我可以unalias在 bash 和 zsh 中删除别名,但是我将如何为一个功能?

回答by ennuikiller

unset -f my_function

will remove (or unset) the function my_function

将删除(或取消设置)函数 my_function

回答by theoden8

unfunction my_functionin zsh

unfunction my_functionzsh

Perhaps, I'm a bit late in this good old '15, but this feature persists.

也许,我在这个 15 年的美好时光中有点晚了,但这个功能仍然存在。