无法取消 rm 别名并使其成为 Zsh 中的函数
我在 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
其他人都说得对,你只是没有别名。 更重要的是:
不要这样做。 有一天你会在另一台遵循 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.
您应该只尝试删除存在的别名。
立即创建一个非别名的别名让我觉得很难看。
我的建议是测试 rm 是否为别名,如果是,则测试 rm 是否为别名。
或者使用暴力并忽略 stderr
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.
Or use brute force and ignore stderr with
该错误消息是因为您尝试取消别名
rm
并且没有这样的别名。由于您可以多次使用别名而不会出现错误,因此我会将您的代码更改为:
这保证了在尝试取消别名之前
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:
That guarantees that
rm
exists as an alias before you try to unalias it.我对 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.