2

I have this if statement and every time I change something another thing seems to be wrong. Can you see the problem?

if [[ $(ps -ef | grep "Process" | grep -v "grep" | awk '{print $2}') = '' ]]; then
        echo "bien"
fi

I get launcher.sh[74]: 11927676^J15335522: syntax error

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
lucia
  • 83

2 Answers2

2

If "Process" is a fixed string, try

ps -ef | awk '/[p]rocess/ {print $2}'

to get process id.

If you are checking for a missing process ( ... = '' )

if ps -ef | grep -q [P]rocess
then 
   echo Process present
else
   echo Process absent
fi

You might also have a look at pgrep(1) (e.g. man pgrep )

Archemar
  • 31,554
0

Comparison in KSH needs to be done with two equal signs. ==

if [[ $(ps -ef | grep "Process" | grep -v "grep" | awk '{print $2}') == '' ]]; then
        echo "bien"
fi
Peschke
  • 4,148