1

在阅读了最近在 SO 上回答的问题后,我想要一种快速简单的方法来检查我的 IP 地址。为了将来参考,有没有办法使以下别名起作用?

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

3 回答 3

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

您需要在别名中使用单引号来阻止 bash 尝试解释其中的部分代码。在处理别名本身的内容时,双引号上的转义符会被去除。

于 2009-03-06T07:34:49.300 回答
6

引用内部双引号:

alias myip='python -c "from urllib import urlopen; print urlopen(\"http://whatismyip.appjet.net\").read()[:-1]"'
于 2009-03-06T07:34:21.813 回答
5

也可以用 curl 完成:

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

或使用 wget:

alias myip='wget -O - "http://whatismyip.appjet.net" 2>/dev/null'
于 2009-03-06T08:19:46.247 回答