bash Linux 别名链命令(可以避免递归吗?)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7715939/
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:56:26  来源:igfitidea点击:

Linux alias chain commands (can recursion be avoided?)

linuxbashshellalias

提问by GoTTimw

I've been looking around for ways to alias clear and ls into one command. Currently I've defined command x:

我一直在寻找将 clear 和 ls 别名为一个命令的方法。目前我已经定义了命令 x:

alias x="clear;ls"

Now is there any walkaround to avoid recursion and define:

现在是否有任何解决方法可以避免递归并定义:

 alias ls='clear;ls'

回答by Jonathan

If you put a backslash before the command name, that will disable any aliases.

如果在命令名称之前放置反斜杠,则会禁用任何别名。

alias ls='clear;\ls'

Or, like Arnaud said, just use the full path for ls.

或者,就像 Arnaud 所说的,只需使用 ls 的完整路径。

回答by jpalecek

Another way of doing this would be

另一种方法是

alias ls='clear; command ls'

This is different from /usr/bin/ls, as it still searches lsin the $PATH, but will ignore shell functions or aliases.

这与 不同/usr/bin/ls,因为它仍然ls在 中搜索$PATH,但会忽略 shell 函数或别名。

回答by Arnaud F.

Just do :

做就是了 :

alias ls='clear;/usr/bin/ls'

When typing:

打字时:

$ ls

First of all it will search an user defined function, it will launch it, else search in $PATH commands.

首先它将搜索用户定义的函数,它将启动它,否则在 $PATH 命令中搜索。

By giving the explicit path of the lscommand, recursion will be avoided.

通过给出ls命令的明确路径,将避免递归。