LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script - check if three commands are true (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-check-if-three-commands-are-true-4175532615/)

edsmith123 01-31-2015 11:14 AM

Bash script - check if three commands are true
 
I am trying to check if all three mountpoint commands return true. However when I run the bash script I get a binary operator expected error.

if [[ mountpoint -q /mnt/foo1 && mountpoint -q /mnt/foo2 && mountpoint -q /mnt/foo3 ]]
then
echo "all three true"
else
echo "all three not true"
fi

Miati 01-31-2015 11:21 AM

Quote:

Originally Posted by edsmith123 (Post 5309542)
if [[ mountpoint -q /mnt/foo1 && mountpoint -q /mnt/foo2 && mountpoint -q /mnt/foo3 ]]

Should be seperate.

Code:

if mountpoint -q /mnt/foo1 && mountpoint -q /mnt/foo2 && mountpoint -q /mnt/foo3
    then
        commands
fi

edit: removed [], seems to work in this circumstance.

From man bash

Quote:

Conditional expressions are used by the [[ compound command and the
test and [ builtin commands to test file attributes and perform string
and arithmetic comparisons.
Since you're not looking to do any of the above and just looking for whether the command succeeds or fails, you don't need the []. There may be a more correct way.

edsmith123 01-31-2015 11:24 AM

I get the same binary operator error using that syntax as well.

edsmith123 01-31-2015 11:49 AM

Got it working with the following:

if [[ $(mountpoint /mnt/foo1) && $(mountpoint /mnt/foo2) && $(mountpoint /mnt/foo3) ]]


All times are GMT -5. The time now is 11:22 PM.