Joined: Jan. 2007
||Posted: Jan. 19 2007,10:40
I'm trying to examine the results of a ping to determine if there was a packet lost. But, I'm having trouble getting a bash pattern to work when there is a space in the pattern.
sResult=$(ping -c 1 192.168.0.120)
if [[ $sResult == *packet* ]]
echo packet found
echo packet not found
But, if I try to search for "packet loss", I can't get it work.
Bash gives a syntax error if I use the statement:
if [[ $sResult == *packet loss* ]]
if [[ $sResult == "*packet loss*" ]]
if [[ $sResult == '*packet loss*' ]]
if [[ $sResult == *packet\sloss* ]]
I've also tried searching Google for bash pattern expressions and haven't found any helpful documentation. No one seems to ever search a string that contains spaces.
And yes, I know I can pipe the result of pipe and use grep. But, I'm trying to relearn bash scripting (it been an extremely long time) and I would like to get it work if possible.
Can someone help me out?