tags:

views:

361

answers:

3

I want a quick an easy way to check my ip address after reading a recent question that had been answered on SO. For future reference, is there a way to make the following alias work?

alias myip='python -c "from urllib import urlopen; print urlopen("http://whatismyip.appjet.net").read()[:-1]"'
+6  A: 

Quote the inside double-quotes:

alias myip='python -c "from urllib import urlopen; print urlopen(\"http://whatismyip.appjet.net\").read()[:-1]"'
You two answered at the same time, but kevinbutler has less rep. Answer goes to the little guy. Thanks to the both of you.
vgm64
+7  A: 
alias myip="python -c 'from urllib import urlopen; print urlopen(\"http://whatismyip.appjet.net\").read()[:-1]'"

You need to use single quotes inside the alias to stop bash trying to interpret parts of your code inside them. The escapes on the double quotes get stripped out while processing what the alias itself is.

Matthew Scharley
Scratch that, monoxide got in first!
vgm64
+4  A: 

could also be done with curl:

alias myip='curl "http://whatismyip.appjet.net"'

or using wget:

alias myip='wget -O - "http://whatismyip.appjet.net" 2>/dev/null'
Patrick