Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alias with parameters

Tags:

linux

shell

zsh

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
like image 837
ceth Avatar asked May 25 '10 12:05

ceth


2 Answers

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 …).

like image 156
Michael Krelin - hacker Avatar answered Oct 14 '22 06:10

Michael Krelin - hacker


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
like image 26
Dave Avatar answered Oct 14 '22 08:10

Dave