Bash OR operator












0















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'










share|improve this question

























  • I've edited the post to show the errors I'm seeing

    – user57649
    Jan 9 at 21:39
















0















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'










share|improve this question

























  • I've edited the post to show the errors I'm seeing

    – user57649
    Jan 9 at 21:39














0












0








0








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'










share|improve this question
















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'







bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 10 at 18:59









Rui F Ribeiro

39.5k1479133




39.5k1479133










asked Jan 9 at 21:31









user57649user57649

346




346













  • I've edited the post to show the errors I'm seeing

    – user57649
    Jan 9 at 21:39



















  • I've edited the post to show the errors I'm seeing

    – user57649
    Jan 9 at 21:39

















I've edited the post to show the errors I'm seeing

– user57649
Jan 9 at 21:39





I've edited the post to show the errors I'm seeing

– user57649
Jan 9 at 21:39










1 Answer
1






active

oldest

votes


















1














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


or



$ 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





share|improve this answer


























  • 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













  • That fixed. Thanks.

    – user57649
    Jan 9 at 21:54











  • 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








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493556%2fbash-or-operator%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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


or



$ 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





share|improve this answer


























  • 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













  • That fixed. Thanks.

    – user57649
    Jan 9 at 21:54











  • 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
















1














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


or



$ 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





share|improve this answer


























  • 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













  • That fixed. Thanks.

    – user57649
    Jan 9 at 21:54











  • 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














1












1








1







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


or



$ 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





share|improve this answer















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


or



$ 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






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 10 at 15:30

























answered Jan 9 at 21:40









DopeGhotiDopeGhoti

44.2k55683




44.2k55683













  • 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













  • That fixed. Thanks.

    – user57649
    Jan 9 at 21:54











  • 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



















  • 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













  • That fixed. Thanks.

    – user57649
    Jan 9 at 21:54











  • 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

















That's giving this error: /home/tiger/bin/pauseMusic.sh: line 3: syntax error near unexpected token `||'

– user57649
Jan 9 at 21:46





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







@user57649 Leave out the >. Its a leftover from copy. My pgrep does not support the option -q.

– Ralf
Jan 9 at 21:48















That fixed. Thanks.

– user57649
Jan 9 at 21:54





That fixed. Thanks.

– user57649
Jan 9 at 21:54













There is still the q in the last two examples :-).

– Ralf
Jan 10 at 6:26





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





♫ Copypasta my old friend / You show my laziness again... ♫

– DopeGhoti
Jan 10 at 15:32


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f493556%2fbash-or-operator%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Morgemoulin

Scott Moir

Souastre