Jos*_*muk 8 command-line alias
我想在别名中插入不同可能的拼写变体,例如cat
命令。我可以使用一些符号来表示“或”还是应该在新行上?
alias at|cart|cst '/bin/cat'
Run Code Online (Sandbox Code Playgroud)
mur*_*uru 17
帮助alias
表明它可以一次分配多个别名:
alias: alias [-p] [name[=value] ... ]
Define or display aliases.
Without arguments, `alias' prints the list of aliases in the reusable
form `alias NAME=VALUE' on standard output.
Otherwise, an alias is defined for each NAME whose VALUE is given.
A trailing space in VALUE causes the next word to be checked for
alias substitution when the alias is expanded.
Run Code Online (Sandbox Code Playgroud)
所以你可以使用大括号扩展来生成name=value
对:
alias {at,cart,cst}='/bin/cat'
Run Code Online (Sandbox Code Playgroud)
所以:
$ alias {at,cart,cst}='/bin/cat'
$ type at cart cst
at is aliased to `/bin/cat'
cart is aliased to `/bin/cat'
cst is aliased to `/bin/cat'
Run Code Online (Sandbox Code Playgroud)
也就是说,查看 zsh,它具有内置的错字更正(这对 没有帮助at
,但对其他人有帮助):
Run Code Online (Sandbox Code Playgroud)% setopt correct % sl zsh: correct `sl' to `ls' [nyae]? y % setopt correctall % ls x.v11r4 zsh: correct `x.v11r4' to `X.V11R4' [nyae]? n /usr/princton/src/x.v11r4 not found % ls /etc/paswd zsh: correct to `/etc/paswd' to `/etc/passwd' [nyae]? y /etc/passwd
如果
y
在 shell 询问您是否要更正某个单词时按,它将被更正。如果您按n
,它将被单独留下。按a
中止命令,并按下e
带来阵容再次编辑,如果你同意这个词拼写错了,但你不喜欢的修正。
我认为您不能一次分配多个别名。
但是您可以循环遍历这样的列表:
for a in cart xat vat xst cst vst dog; do alias "$a"='/bin/cat'; done
Run Code Online (Sandbox Code Playgroud)
确保别名尚未被其他程序使用(如 at
您的示例)。