I use a Linux (Ubuntu) bash.
When I ping an address dirrectly – all work fine.
But when I use it with a variable that gets it’s value from calculation – it fails.
what am i doing wrong?
network=`ip r | grep default | awk '{print $3;}'`
echo $network # prints: 10.0.0.138
ping $network # prints: ping: 10.0.0.138: Name or service not known (ERROR???)
ping 10.0.0.138 # prints: PING 10.0.0.138 (10.0.0.138) 56(84) bytes of data. (OK)
2
Answers
it's becaues the result is colored...
ip
is aliased toip -c
so - this had solved the issue:
That sequence should work OK at the command line (it’d be interesting to see a screenshot). However you can lose the grep and use a more rigorous awk script:
Then just send a single echo-request without any name resolution: