bash 将 curl 的输出分配给变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9764571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:48:27 来源:igfitidea点击:
Assign output of curl to variable
提问by user1277716
How do assign the output of curl to a variable so that I can use it in sendEmail
如何将 curl 的输出分配给一个变量,以便我可以在 sendEmail 中使用它
IP=curl ifconfig.me
sendEmail -f [email protected] -t [email protected] -s smtp.gmail.com -xu [email protected] -xp password -m "This is my IP adress:$IP"
回答by bcarlso
Enclose your curl command in backticks.
用反引号将 curl 命令括起来。
IP=`curl ifconfig.me`
Brandon
布兰登
回答by Kevin
Use $(...):
使用$(...):
IP=$(curl ifconfig.me)
...

