简短回答:默认的 Bash alias 不支持参数。
在 Ubuntu(Bash)里,alias 只是文本替换,例如:
alias ll='ls -l'
执行 ll 时,Bash 直接替换成 ls -l。
但像下面这样是不行的:
alias grep='grep --color=auto $1' # ❌ 不支持 $1
$1 不会被当作参数解析。
grepo() {
grep --color=auto "$1" file.txt
}
使用:
grepo hello
函数支持参数、引号、复杂逻辑。
alias g='grep'
g() {
grep --color=auto "$@"
}
(其实直接用函数更清晰)
xargs(不推荐)alias findpy='find . -name'
findpy "*.py"
这能“看起来像带参数”,但本质是拼接命令。
| 方式 | 是否支持参数 |
|---|---|
| alias | ❌ 不支持 |
| function | ✅ 支持 |
| alias + 函数 | ✅ 支持 |
结论:
如果你需要在 Ubuntu 里“带参数的快捷命令”,请直接用 shell 函数,而不是 alias。
如果你有具体想实现的命令,我可以帮你写。