How do I put the output of the echo statement and the arp statement on the same line?

How can I get the output "echo" and "macaddress" on the same line? This is what I have:

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

      

This is the conclusion:

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 

      

+3


source to share


2 answers


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



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

+1


source


this should do the output on one line



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

      

+2


source







All Articles