开发者

Linux alias chain commands (can recursion be avoided?)

I've been look开发者_如何学运维ing around for ways to alias clear and ls into one command. Currently I've defined command x:

alias x="clear;ls"

Now is there any walkaround to avoid recursion and define:

 alias ls='clear;ls'


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.


Another way of doing this would be

alias ls='clear; command ls'

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


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.

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


There is no direct recursion in alias. From man bash:

The first word of the replacement text is tested for aliases, but a word that is identical to an alias being expanded is not expanded a second time. This means that one may alias ls to ls -F, for instance, and bash does not try to recursively expand the replacement text.


I always use ls with --color=auto parameter ( -G Enable colorized output.) and like to use functions.

clear_and_ls() {
    clear
    command ls --color=auto
}

alias ls="clear_and_ls"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜