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"

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

  • I guess you are missing the $ in (ps. It should be $(ps. Also add what you have tried and the errors you are having to the question. – BitsOfNix Oct 1 '15 at 11:07
  • it doesn't work.. :( – lucia Oct 1 '15 at 11:18

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
   echo Process present
   echo Process absent

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


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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.