PDA

View Full Version : bash scripts



AmoRico
31-01-2005, 15:29
First of all. I think it would be nice to make a tread just for scripts. And here comes my question



#!/bin/sh

P1="ping -c 1 10.26.1.1 | grep 'packets' | sed -e 's/ packets received.*//' | sed -e 's/.*transmitted, //'"
P2="1"

if [ "$P1" = "$P2" ]; then
echo SUPER
else
echo SUCKS
fi


Even when I get "1" if I do just ping -c 1 10.26.1.1 | grep 'packets' | sed -e 's/ packets received.*//' | sed -e 's/.*transmitted, //', I cannot get it to work in this script. I am a bigginer, so I know I must be doing something wrong, can someone help me? I should get "SUCKS" when there is no packet received and "SUPER" when received.

Thx 4 help.

sodb
31-01-2005, 16:09
Use back quotes (`) instead of double quotes (") around instructions that need to be executed in a script. You might than also replace the single qutoes (') with double quoted ("). Furthermore, the -e options in sed can be concatenated.

P1=`ping -c 1 10.26.1.1 | grep "packets" | sed -e "s/ packets received.*//" -e "s/.*transmitted, //"`

AmoRico
31-01-2005, 19:45
Thanks! It is working...