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?
在阅读了最近在SO上回答的问题之后,我想快速简单地检查我的IP地址。为了将来参考,有没有办法使以下别名工作?
alias myip='python -c "from urllib import urlopen; print urlopen("http://whatismyip.appjet.net").read()[:-1]"'
3 个解决方案
#1
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.
您需要在别名中使用单引号来阻止bash尝试解释其中的部分代码。在处理别名本身时,双引号上的转义被剥离。
#2
Quote the inside double-quotes:
引用里面的双引号:
alias myip='python -c "from urllib import urlopen; print urlopen(\"http://whatismyip.appjet.net\").read()[:-1]"'
#3
could also be done with curl:
也可以用curl完成:
alias myip='curl "http://whatismyip.appjet.net"'
or using wget:
或使用wget:
alias myip='wget -O - "http://whatismyip.appjet.net" 2>/dev/null'
#1
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.
您需要在别名中使用单引号来阻止bash尝试解释其中的部分代码。在处理别名本身时,双引号上的转义被剥离。
#2
Quote the inside double-quotes:
引用里面的双引号:
alias myip='python -c "from urllib import urlopen; print urlopen(\"http://whatismyip.appjet.net\").read()[:-1]"'
#3
could also be done with curl:
也可以用curl完成:
alias myip='curl "http://whatismyip.appjet.net"'
or using wget:
或使用wget:
alias myip='wget -O - "http://whatismyip.appjet.net" 2>/dev/null'