if inside while statement (PLZ HELP)

hey guys i need some help here i am trying to do a bash shell script to get a parent PID and then search for all childs and kill them all without killing the parent, my problem is in the loop it seems that i dont know how to make a if statment inside a while statment it does not give me what i want.

#!/bin/bash

raqam=$(lui | grep EQUATION | nawk '{print $2}') # this will give me the parent PID

ps -ef | grep "$raqam" | nawk '{print $2}' > dump #dumping all PIDs of parent and child to dump

cat dump | while read line
do
        if $line = $raqam
        then
                #i want here to skip this process ID
        fi

kill -9 $line

done

in the

cat dump | while read line

is my problem i want the script to read every line and execute kill -9 for whats written in the file unless the line is = to $raqam .

can anyone here help plz

Hi,

the problem is that the pipe creates a new sub-shell...try using parenthesis:

cat dump | (while read line
do
        if $line = $raqam
        then
                #i want here to skip this process ID
        fi

kill -9 $line

done)

Not sure I'm getting you ...

cat dump | while read line
do
    if [ "$line" != "$raqam" ]
    then
        kill -9 $line
    fi
done

Don't try to win the Useless Use of Cat Award :slight_smile:

while read line
do
    if [ "$line" != "$raqam" ]
    then
        kill -9 $line
    fi
done < dump

i like the award .. congrats dr.house

do we have useless use of syg commands award??

Thanks - but I prefer to focus on replies more essential :cool: