[英]Combining two bash commands
If found this code 如果找到此代码
host raspberrypi | grep 'address' | cut -d' ' -f4
which gives pi Ip address 给出pi IP地址
and this 和这个
wget --post-data="PiIP=1.2.3.4" http://dweet.io/dweet/for/cycy42
which sends 1.2.3.4 off to dweet.io stream 发送1.2.3.4到dweet.io流
How can I get the output from 1st to replace the 1.2.3.4 in second please? 我怎样才能从1st得到输出,以取代1st中的1.2.3.4?
Save the output of the first command in a variable: 将第一个命令的输出保存在变量中:
ip=$(host raspberrypi | grep 'address' | cut -d' ' -f4)
wget --post-data="PiIP=$ip" http://dweet.io/dweet/for/cycy42
Btw, if your raspberrypi is running raspbian, then a much cleaner way to get the IP address: 顺便说一句,如果您的raspberrypi正在运行raspbian,那么获取IP地址的一种更简洁的方法:
hostname -I
Simplifying the commands to: 将命令简化为:
ip=$(hostname -I)
wget --post-data="PiIP=$ip" http://dweet.io/dweet/for/cycy42
Making that a one-liner: 使之成为一线:
wget --post-data="PiIP=$(hostname -I)" http://dweet.io/dweet/for/cycy42
UPDATE UPDATE
So it seems hostname -I
gives a bit different output for you. 看来
hostname -I
为您提供了一些不同的输出。 You can use this then: 然后可以使用它:
ip=$(hostname -I | awk '{print $1}')
To make it a one-liner, you can insert this into the second line just like I did in the earlier example. 要使其成为单线,可以像在前面的示例中一样将其插入第二行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.