samedi 3 octobre 2015

Problems compairing strings (BASH)

I'm trying to compare 2 strings. One comes from a file through the grep command and the other one never changes because I'm always compairing it with the ones I create while reading file texts. if they are equal, the program should print the data asociated with the content that the new string contains. I've tried with all the syntax that bash allows (cause I'm new at bash) but it just not working. It looks like the second if doesn't work, because I tried earlier without that and only print the strings (echo $text) and it worked, but not the proper way as the excercise I'm doing asks for. I have to show in the console only the pid and state of the processes that are running.

cd
cd /proc
run="State: S (sleeping)"
for i in $( ls -d */); 
do
    cd $i
    if [ -f /proc/$i/status ];
        then    text="`grep -w "S" status`"
             if [ "$text" == "$run" ]
                then grep -w "Pid" status
                     grep -w "State" status
             fi
             cd /proc
        else cd /proc
    fi
done
;;

Aucun commentaire:

Enregistrer un commentaire