在简单的情况下,您可以重复别名。根据手册:
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.
因此,这是有效的:
user@host: alias f='echo foo'
user@host: f
foo
user@host: alias g='f bar'
user@host: g
foo bar
在更复杂的情况下,您应该切换到函数。例如:
e() {
eza --long --recurse --dereference "$@"
}
et() {
e "$@" --tree
}
请注意,函数几乎总是比别名更受欢迎,因为函数通常更容易编写(不需要额外的引号或特殊字符的转义),并且在支持参数方面更灵活。手册中Aliases条目的最后一行甚至指出:
For almost every purpose, shell functions are preferred over aliases.