-1

I have a VPS and an associated IP address for it. I'm doing a lot of work with it in my bash shell and I'm wondering if there's some way I can create either an alias or a environmental shortcut for the IP address to avoid having to type it every time. How would I do this?

Casey Flynn
  • 217
  • 4
  • 13

3 Answers3

4

Add to your ~/.bashrc:

export myip="1.2.3.4"

Then you can use $myip on the command line after logging in or running source ~/.bashrc:

ping $myip

Aliases only work as commands, so you use it to replace commands which might include your IP:

alias myping='ping 1.2.3.4'
alias myssh='ssh user@1.2.3.4'
Cakemox
  • 25,209
  • 6
  • 44
  • 67
2

export somevarname="someIPaddress" should do what you want. after you do that, you should be able to use $somevarname instead. Note that the export should stay around for your current shell. If you log out, you'll have to set it again on login (or set it in your profile/bashrc)

draeath
  • 366
  • 1
  • 6
2

Assuming you're connecting via ssh:

export foo=`echo $SSH_CONNECTION  | awk '{print $3}'`
echo $foo

This way you don't need to "preset" the IP for each machine. Put that in your .bashrc or .bash_profile or wherever you like.

DictatorBob
  • 1,644
  • 11
  • 15