Monday, November 23, 2015

Unix Shell: Use of functions to create complicated aliases

In *nix shells it sometimes useful to create aliases that receive parameters.
This can be done using functions:

# ssh with password and without host signature checking
function pssh() {/usr/bin/sshpass -p PASSWORD /usr/bin/ssh -oStrictHostKeyChecking=no USERNAME@$1}
# ssh with private key
function kssh() {/usr/bin/ssh -oStrictHostKeyChecking=no -i ~/.ssh/key.pem USERNAME@$1}
view raw .zshrc hosted with ❤ by GitHub


Now you can type just something like: kssh 192.168.1.1 or pssh 192.168.1.2

No comments: