LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 02-18-2013, 06:54 AM   #1
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85
Blog Entries: 1

Rep: Reputation: Disabled
Simple if - else logic problem?? - Newbie


Why doesnt this work? - just looking to understand if/else statements (am checking for Mutt, then asking to install, no install commands yet, just using echo to see if it will work logically)
Code:
#!/bin/bash

dpkg -s mutt 2>error
if [[ $? -eq 1 ]]
 then
    echo "install now y/n"
    read entry1
   if [[ "$entry1" == "Y" || "$entry1 == "y" ]]
    then
     echo "INSTALLING/n INSTALLING/n/n/n/n/n"
   else
    echo "You need Mutt for program to work/n/n"
    echo "Exiting to main menu"
sleep 3s
fi
else
echo "installed already exiting in 3,2,1...."
fi
exit 0

Last edited by Batistuta_g_2000; 02-18-2013 at 07:21 AM.
 
Old 02-18-2013, 07:15 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
#!/bin/bash
set -x
...
for starters. Then analyze the output on the screen when you run the script interactively.

Please let us know...

Edit:
Please use [code][/code] tags around script(s) or their output.
Thank you.

Last edited by Habitual; 02-18-2013 at 07:16 AM.
 
Old 02-18-2013, 07:20 AM   #3
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
for starters. Then analyze the output on the screen when you run the script interactively.

Please let us know...

Edit:
Please use [code][/code] tags around script(s) or their output.
Thank you.
Not much more in output: I'm not sure about the order I have: if-then-if-then-else-fi-fi
So dpkg gives true/false, if true read input, if false exit, if input Y do something, if input anything else exit.....Help appreciated.

UBUNTU::./mutt
+ dpkg -s mutt
./mutt: line 12: conditional binary operator expected
./mutt: line 12: syntax error near `"You'
./mutt: line 12: ` echo "You need Mutt for program to work/n/n"'
 
Old 02-18-2013, 07:26 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
You missed a quote here:
Code:
if [[ "$entry1" == "Y" || "$entry1" == "y" ]]
 
Old 02-18-2013, 07:31 AM   #5
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
You missed a quote here:
Code:
if [[ "$entry1" == "Y" || "$entry1" == "y" ]]
You sir....are a hero - many thanks (having some newbie freak-out moments)....
 
Old 02-18-2013, 07:40 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Just to add, bashes if can also take a function directly so you can place your dpkg statement straight the first if:
Code:
if ! dpkg -s mutt 2>error
I do not know much about dpkg, but I am guessing a positive value means its status is not available. Hope this helps.
 
Old 02-18-2013, 08:00 AM   #7
Batistuta_g_2000
Member
 
Registered: Oct 2011
Posts: 85

Original Poster
Blog Entries: 1

Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
Just to add, bashes if can also take a function directly so you can place your dpkg statement straight the first if:
Code:
if ! dpkg -s mutt 2>error
I do not know much about dpkg, but I am guessing a positive value means its status is not available. Hope this helps.
Good one, thanks a lot.
 
  


Reply



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
simple apache mod_rewrite problem (newbie) rtnylw Linux - Server 7 08-08-2009 11:38 AM
LSI Logic / Symbios Logic 53c875 (rev 14) -> HP Storageworks 1/8 G2 gileravxr Linux - Hardware 0 07-21-2009 04:45 AM
Newbie simple installation problem with Mint everyonedoesit Linux - Newbie 2 06-02-2009 04:46 PM
Simple while loop problem (newbie question) Seventh Programming 3 09-07-2004 12:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:12 PM.

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
Open Source Consulting | Domain Registration