如何删除/移除 shell 函数?

发布于 2024-07-07 07:23:31 字数 88 浏览 6 评论 0原文

我已经这样做了:

$ z() { echo 'hello world'; }

我该如何摆脱它?

I have done this:

$ z() { echo 'hello world'; }

How do I get rid of it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捂风挽笑 2024-07-14 07:23:31
unset -f z

将取消设置名为 z 的函数。 有几个人回答说:

unset z

但是如果你有一个函数和一个名为 z 的变量,则只有变量会被取消设置,而函数不会被取消设置。

unset -f z

Will unset the function named z. A couple people have answered with:

unset z

but if you have a function and a variable named z only the variable will be unset, not the function.

风苍溪 2024-07-14 07:23:31

在 Zsh 中:

unfunction z

这是 unhash -f zunset -f z 的另一个(可以说更好)名称,并且与以下家族的其余部分一致:

  • unset
  • unhash
  • unalias
  • unlimit
  • unsetopt

如果对此类事情有疑问,请输入 un查看完整列表。

(稍微相关:拥有像 realasesrefunctionsresetoptsreenv 等来“重新”相应的文件(如果您已将它们分开/分组)。)

In Zsh:

unfunction z

That's another (arguably better) name for unhash -f z or unset -f z and is consistent with the rest of the family of:

  • unset
  • unhash
  • unalias
  • unlimit
  • unsetopt

When in doubt with such things, type un<tab> to see the complete list.

(Slightly related: It's also nice to have functions/aliases like realiases, refunctions, resetopts, reenv, etc to "re-source" respective files, if you've separated/grouped them as such.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文