linux - Bash - Using variable inside command not working -


i not sure why not work. (i researched , found nothing.)

i'm trying ping ip , result. avg time , packet loss result

ping=$(ping -c $amount -s $size $ip) avg_time=$($ping | tail -1 | awk '{print $4}' | cut -d '/' -f 2) packet_loss=$($ping | grep -op '\d+(?=% packet loss)') 

error:

ping: command not found

it works if put ping command inside each of other commands, means ping once each not values 1 ping result.

i have been on many times, think have missed here.

you want output ping command. change to:

avg_time=$(echo "$ping" | tail -1 | awk '{print $4}' | cut -d '/' -f 2) packet_loss=$(echo "$ping" | grep -op '\d+(?=% packet loss)') 

notice echo command above.

with current code, it's trying execute output of first command not want.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -