My script is working with this:

if pgrep -f "/home/tiger/bin/pymp" >/dev/null 2>&1 ; then

I want it to check for mpv2 also.

This is what I have so far:

if [[ /usr/bin/pgrep -f "/home/tiger/bin/pymp" ]] || [[ /usr/bin/pgrep -f "/usr/bin/mpv2" ]] >/dev/null 2>&1; then

These are the errors I'm seeing:

/home/tiger/bin/pauseMusic.sh: line 3: conditional binary operator expected /home/tiger/bin/pauseMusic.sh: line 3: syntax error near -f' /home/tiger/bin/pauseMusic.sh: line 3:if [[ /usr/bin/pgrep -f "/home/tiger/bin/pymp" ]] || [[ /usr/bin/pgrep -f "/usr/bin/mpv2" ]] >/dev/null 2>&1; then'

  • I've edited the post to show the errors I'm seeing – user57649 Jan 9 at 21:39

The [[ and ]] operators are for explicit comparative tests. If you want to check two command results, just use the shell:

$ if /usr/bin/pgrep -fq "/home/tiger/bin/pymp" || /usr/bin/pgrep -fq "/usr/bin/mpv2" ; then do_stuff; fi

Not all versions of pgrep support the -q argument to suppress output. If this is the case for you, you can suppress each pgrep individually or combine the redirection:

$ if { /usr/bin/pgrep -f "/home/tiger/bin/pymp" || /usr/bin/pgrep -f "/usr/bin/mpv2";} > /dev/null 2>&1 then do_stuff; fi


$ if /usr/bin/pgrep -f "/home/tiger/bin/pymp" > /dev/null 2>&1 || /usr/bin/pgrep -f "/usr/bin/mpv2" > /dev/null 2>&1 ; then do_stuff; fi
  • That's giving this error: /home/tiger/bin/pauseMusic.sh: line 3: syntax error near unexpected token `||' – user57649 Jan 9 at 21:46
  • @user57649 Leave out the >. Its a leftover from copy. My pgrep does not support the option -q. – Ralf Jan 9 at 21:48
  • There is still the q in the last two examples :-). – Ralf Jan 10 at 6:26
  • ♫ Copypasta my old friend / You show my laziness again... ♫ – DopeGhoti Jan 10 at 15:32

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.