Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm stuck with a simple script. I want to run tracepath on multiple address and to find if some IP is contained in the output of the tracepath. For now I have the following:

if tracepath -n google.com | grep x.x.x.x 
echo bal bal 
echo ova ova ova

But this doesn't work.

share|improve this question
what are you trying to grep for? your regexp says 'x' then any character then 'x' … –  richard Aug 30 at 14:44

2 Answers 2

up vote 2 down vote accepted

Try this syntax and I think you don't want the output of grep, so we use the -q (quiet) switch:

(traceroute -n google.com | grep -q x.x.x.x) && echo "Yes" || echo "Nope"

Or with the if statement:

if (traceroute -n google.com | grep -q x.x.x.x)
  echo "Yes"
 echo "Nope"
share|improve this answer
Yup it work perfect ! Im trying now to put the echo in newline, i have the following ... echo "This $i is OK" and $i is the ip address so when i use "\n" it does not work and when i use '' instead of "" the $i is showing instead of the actual ip addrees ( or value ) –  user3523605 Aug 30 at 15:28
Found solution about this too ... echo -e "This $i is OK \n" :) –  user3523605 Aug 30 at 15:36
The parentheses are superfluous. @user3523605 –  Gilles Aug 30 at 23:04

I think you should consider reading basics of if-else first.....LOL you even have the wrong syntax, and I wonder what bal bal and ova ova ova mean.....LOL

tracepath -n google.com | grep x.x.x.x
if [ $? -eq 0 ]
echo "bal bal" 
echo "ova ova ova"
share|improve this answer
-1 as rude your code is equivalent. –  richard Aug 30 at 14:44
This code is exactly equivalent to the code in the question. –  Gilles Aug 30 at 23:05
@Gilles Oh is it???? I've tried it out for real. Code in the question doesnt work, but mine works. What is this do doing in the if-else statement??? –  Colonial Dunky Aug 31 at 18:11
Oh, sorry. Yes, do should be then. Your answer would be useful if it pointed that out instead of insulting the asker. –  Gilles Aug 31 at 19:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.