alias with parameters

2019-03-18 01:41发布

If there is any possibility to use the parameters in zsh aliases? Something like this:

 alias ssh_nokia="ssh root@<ip_parameter>"

Usage:

 ssh_nokia 192.168.1.2

标签: linux shell zsh
2条回答
叛逆
2楼-- · 2019-03-18 01:54

In your particular case edit ~/.ssh/config (See Dave's answer below), or use:

alias ssh_nokia='ssh -l root'

Generally

ssh_nokia() {
    ssh root@"$@"
}

is equivalent to alias (will produce ssh root@1stparam 2ndparam 3rdparam …).

查看更多
Ridiculous、
3楼-- · 2019-03-18 02:06

I would use up ~/.ssh/config to create an alias for a particular connection, like so:

Host=anyoldname
Hostname=[hostname or ip address]
User=root

Then you can:

$ ssh anyoldname

More info:

$ man ssh_config
查看更多
登录 后发表回答