Bash OR operator
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'
if [[ /usr/bin/pgrep -f "/home/tiger/bin/pymp" ]] || [[ /usr/bin/pgrep -f "/usr/bin/mpv2" ]] >/dev/null 2>&1; then'
/home/tiger/bin/pauseMusic.sh: line 3:
bash
add a comment |
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'
if [[ /usr/bin/pgrep -f "/home/tiger/bin/pymp" ]] || [[ /usr/bin/pgrep -f "/usr/bin/mpv2" ]] >/dev/null 2>&1; then'
/home/tiger/bin/pauseMusic.sh: line 3:
bash
I've edited the post to show the errors I'm seeing
– user57649
Jan 9 at 21:39
add a comment |
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'
if [[ /usr/bin/pgrep -f "/home/tiger/bin/pymp" ]] || [[ /usr/bin/pgrep -f "/usr/bin/mpv2" ]] >/dev/null 2>&1; then'
/home/tiger/bin/pauseMusic.sh: line 3:
bash
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'
if [[ /usr/bin/pgrep -f "/home/tiger/bin/pymp" ]] || [[ /usr/bin/pgrep -f "/usr/bin/mpv2" ]] >/dev/null 2>&1; then'
/home/tiger/bin/pauseMusic.sh: line 3:
bash
bash
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
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. Mypgrep
does not support the option-q
.
– Ralf
Jan 9 at 21:48
That fixed. Thanks.
– user57649
Jan 9 at 21:54
There is still theq
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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. Mypgrep
does not support the option-q
.
– Ralf
Jan 9 at 21:48
That fixed. Thanks.
– user57649
Jan 9 at 21:54
There is still theq
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
add a comment |
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
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. Mypgrep
does not support the option-q
.
– Ralf
Jan 9 at 21:48
That fixed. Thanks.
– user57649
Jan 9 at 21:54
There is still theq
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
add a comment |
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
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
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. Mypgrep
does not support the option-q
.
– Ralf
Jan 9 at 21:48
That fixed. Thanks.
– user57649
Jan 9 at 21:54
There is still theq
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
add a comment |
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. Mypgrep
does not support the option-q
.
– Ralf
Jan 9 at 21:48
That fixed. Thanks.
– user57649
Jan 9 at 21:54
There is still theq
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
I've edited the post to show the errors I'm seeing
– user57649
Jan 9 at 21:39