在syntax
中,您可以定义全局别名。例如,
zsh
然后像这样使用它们:
alias -g G='| grep'
alias -g W='| wc -l'
可以在some_command G some_text W
中以某种方式模拟全局别名吗?
答案 0 :(得分:5)
Assuming you never want to use capital G for any other purpose, you could add this to your .bashrc
file:
bind '"G": "| grep"'
This will expand G to | grep
as soon as you type it. That is, Shift+g no longer produces a capital G, but the string | grep
. You'd want to choose a longer sequence that you would never expect to otherwise type, either by itself or as part of another word.
答案 1 :(得分:1)
您可以将其保存到变量
中g='| grep'
然后,你的命令可能是
eval some_command $G some_text
OR
some_command $G some_text
Ctrl + Alt + E (在其他系统上,seems to be?{{1}并且是可配置的)
将命令扩展为所需的ctrl+x+*
,然后按Enter键。不应该扩展的变量必须是单引号。
虽然没有像zsh那样的东西。