gpt4 book ai didi

linux - 如何将 echo 语句和 arp 语句的输出放在一行中?

转载 作者:太空狗 更新时间:2023-10-29 11:08:22 25 4
gpt4 key购买 nike

如何在一行中获得输出“echo”和“macaddress”?这是我得到的:

ipRange="192.168.0."
macaddress= arp | grep -w "$ipRange$1" | awk '{print $3,$1}'

ping -c1 "$ipRange$1" > /dev/null
if [ $? -eq 0 ]; then
echo "deze host met mac address en ip address is up $macaddress"
else
echo "het is down"
fi

这是输出:

VirtualBox ~ $ bash test2.sh 149
e0:b9:a5:f8:24:c3 192.168.0.149
deze host met mac address en ip address is up

最佳答案

这应该在单行输出

ipRange="192.168.0."
macaddress=$(arp | grep -w "$ipRange$1" | awk '{print $3,$1}')

ping -c1 "$ipRange$1" > /dev/null
if [ $? -eq 0 ]; then
echo "deze host met mac address en ip address is up $macaddress"
else
echo "het is down"
fi

关于linux - 如何将 echo 语句和 arp 语句的输出放在一行中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30830715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com