LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-31-2015, 12:14 PM   #1
edsmith123
LQ Newbie
 
Registered: Apr 2013
Posts: 17

Rep: Reputation: Disabled
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

Last edited by edsmith123; 01-31-2015 at 12:49 PM.
 
Old 01-31-2015, 12:21 PM   #2
Miati
Member
 
Registered: Dec 2014
Distribution: Linux Mint 17.*
Posts: 326

Rep: Reputation: 106Reputation: 106
Quote:
Originally Posted by edsmith123 View Post
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.

Last edited by Miati; 01-31-2015 at 12:31 PM.
 
Old 01-31-2015, 12:24 PM   #3
edsmith123
LQ Newbie
 
Registered: Apr 2013
Posts: 17

Original Poster
Rep: Reputation: Disabled
I get the same binary operator error using that syntax as well.
 
Old 01-31-2015, 12:49 PM   #4
edsmith123
LQ Newbie
 
Registered: Apr 2013
Posts: 17

Original Poster
Rep: Reputation: Disabled
Got it working with the following:

if [[ $(mountpoint /mnt/foo1) && $(mountpoint /mnt/foo2) && $(mountpoint /mnt/foo3) ]]
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to end the bash script using commands in bash not manually by pressing ctrl+c Sanpreet Singh Linux - Newbie 1 07-03-2013 02:04 PM
[SOLVED] Bash script to check if file is present or not, check periodically every 30 mins Iyyappan Linux - Server 10 07-03-2013 06:19 AM
Bash Script problem with two TRUE conditions Treikayan Linux - Newbie 11 04-18-2013 06:03 PM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 09:56 AM


All times are GMT -5. The time now is 04:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration