无法取消 rm 别名并使其成为 Zsh 中的函数

发布于 2024-07-18 08:37:47 字数 424 浏览 1 评论 0原文

我在 .zshrc 中运行失败,

unalias rm  
rm() { mv $* /tmp/wastebasket }

我在启动时

/Users/Masi/.zshrc:unalias:34: no such hash table element: rm

发现哈希表问题是 Ubuntu 用于运行帮助。 我不确定该错误是否也适用于 Mac 和 rm 命令。

如何在启动时关闭通知?

I run unsuccessfully in my .zshrc

unalias rm  
rm() { mv $* /tmp/wastebasket }

I get at the startup

/Users/Masi/.zshrc:unalias:34: no such hash table element: rm

I noticed that the hash table problem has been an unresolved bug in Ubuntu for run-help.
I am not sure whether the bug applies to Mac and to rm -command too.

How can you get the notification off at the startup?

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

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

发布评论

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

评论(4

甜味超标? 2024-07-25 08:37:47

其他人都说得对,你只是没有别名。 更重要的是:

不要这样做。 有一天你会在另一台遵循 POSIX 标准的 POSIX 机器上(删除而不“回收”),你会随意删除一些东西并且无法撤消它。 现在就学习 rm 纪律。

Everyone else is right that you simply didn't have an alias. More importantly:

DON'T do this. Some day you will be at another POSIX machine that follows POSIX standards (deleting without "recycling"), and you will casually delete something and have no way to undo it. Learn rm discipline now.

烙印 2024-07-25 08:37:47

您应该只尝试删除存在的别名。
立即创建一个非别名的别名让我觉得很难看。
我的建议是测试 rm 是否为别名,如果是,则测试 rm 是否为别名。

 case $(type rm) in
     (*alias*) unalias rm;;
 esac

或者使用暴力并忽略 stderr

 unalias rm 2>/dev/null

You should only try to remove an alias that exists.
Creating an alias that is unaliased right away strikes me as ugly.
My recommendation is to test for rm being an alias and unaliasing if so.

 case $(type rm) in
     (*alias*) unalias rm;;
 esac

Or use brute force and ignore stderr with

 unalias rm 2>/dev/null
浪漫之都 2024-07-25 08:37:47

该错误消息是因为您尝试取消别名 rm 并且没有这样的别名。

由于您可以多次使用别名而不会出现错误,因此我会将您的代码更改为:

alias rm=x
unalias rm  
rm() { mv $* /tmp/wastebasket }

这保证了在尝试取消别名之前 rm 作为别名存在。

That error message is because you're trying to unalias rm and there is no such alias.

Since you can alias something more than once without an error, I would change your code to be:

alias rm=x
unalias rm  
rm() { mv $* /tmp/wastebasket }

That guarantees that rm exists as an alias before you try to unalias it.

A君 2024-07-25 08:37:47

我对 zsh 不太熟悉,但也许是因为 rm 不是别名,而实际上是驻留在 /bin 中的标准实用程序。

您可以直接为其添加别名,而无需先尝试取消别名,从而覆盖任何先前的别名。

I'm not very familiar with zsh, but perhaps it is because rm is not an alias, but is actually a standard utility residing in /bin.

You could just alias it without attempting to unalias it first, overriding any previous alias.

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