Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep into a variable in bash

Status
Not open for further replies.

9anth3r

ISP
Sep 3, 2002
7
US
Got a quick question,

Right now im executing the command's

ping localhost -c 2 >> backup.tmp
grep '100% loss' backup.tmp


how do i get the grep output (if there is any) into a variable ?

Any tutorials on SH would be much appriciated as would any help.

Florian
 
#!/bin/ksh

myVar=$(ping localhost -c 2 | grep '100% loss')
vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 

Hi,
But since you are greping for a Known Quantity aren't you just really looking for the STATUS of grep whether it found your pattern or not? Why do you need the line stored in a variable?

grep '100% loss' backup.tmp
if [ $? == 0 ]; then
echo &quot;ALL was lost&quot;
fi

 
Thank's guys,

Just switched from C++ to shell scripts and haven't had hardly any sleep, just couldn't think today.

Thanks

Florian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top