我在谷歌上查过这个,但之前似乎没有人问过这个问题。有没有一种方法可以设置别名并将其用作程序的命令行参数?
例如
ssh myserver
并且myserver
定义为我的服务器的ip地址
最佳答案
其实是有办法的。但是您需要定义两个别名。
首先:Bash 手册状态 (LESS=+/'^ALIASES' man bash
)
ALIASES If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion.
还有 documented in POSIX规范Thanks to @gniourf_gniourf对于链接:
If the value of the alias replacing the word ends in a <blank>, the shell shall check the next command word for alias substitution; this process shall continue until a word is found that is not a valid alias or an alias value does not end in a <blank>.
所以,如果定义这两个别名(请保留末尾的空格):
$ alias ssh='ssh '
$ alias myserver='192.168.0.1'
$ set -x
$ ssh myserver
+ ssh 192.168.0.1
清除别名:
$ unalias ssh
$ unalias myserver
注意 1:也记录在 ksh
和 zsh
手册中
注意 2:经测试可在 dash
中正常工作(未找到文档)。
关于linux - 如何使用 bash 别名作为命令行参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36243829/