Bash: If/Else statement in one line

前端 未结 5 1256
遥遥无期
遥遥无期 2021-01-29 19:26

I am trying to check if a process (assume it is called some_process) is running on a server. If it is, then echo 1, otherwise echo 0.

This is the command th

5条回答
  •  庸人自扰
    2021-01-29 20:09

    Use grep -vc to ignore grep in the ps output and count the lines simultaneously.

    if [[ $(ps aux | grep process | grep -vc grep)  > 0 ]] ; then echo 1; else echo 0 ; fi
    

提交回复
热议问题