LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-15-2010, 01:02 PM   #1
soppy
Member
 
Registered: Mar 2008
Location: In your head!
Distribution: Arch Linux
Posts: 165
Blog Entries: 1

Rep: Reputation: 28
Bash Dialog --inputbox issue


Hello all! I've been using dialog for a while now, so I know the ins and outs. However, something strange has happened to me. Whenever I use --inputbox, the variable '$?' will always return a 0 value. This is true whenever I press cancel which should return 1, or escape which should produce a 255. I've even gone and grabbed an example --inputbox script off the internet and tried it, however it always returns 0 as well. Any knowledge on what the problem is? Is it a bug with dialog or bash? I am currently running Slackware-current (updated 10/14/2010) and Dialog 1.1 (which is the default) Thanks in advance!!
 
Old 10-15-2010, 01:29 PM   #2
ckoniecny
Member
 
Registered: Oct 2005
Posts: 162

Rep: Reputation: 30
Seems odd. Have you tried retrieving the lastest "dialog" package? Could be a bug within the utility itself.

Could you post your script for us to review if you've already got the latest "dialog" package?
 
Old 10-15-2010, 01:31 PM   #3
Guillermo Reisch
LQ Newbie
 
Registered: Mar 2010
Location: Montevideo
Distribution: Debian, Ubuntu, knoppix
Posts: 7

Rep: Reputation: 1
Can you put some code? So we can check exactly whats goin on
 
Old 10-15-2010, 07:52 PM   #4
soppy
Member
 
Registered: Mar 2008
Location: In your head!
Distribution: Arch Linux
Posts: 165

Original Poster
Blog Entries: 1

Rep: Reputation: 28
Sorry guys. I had to go to work. Here's the code in question.

Code:
function begin {
loop=0
location=/home/soppy/blah
    dialog --title "Weclome" --backtitle "$version" --msgbox "This will back-up your directory." 11 60
    while [ $loop != 1 ]; do
    if [ -d $location ]
    then
    dialog --title "YAY" --backtitle "$version" --infobox "The directory was found at $location." 10 60
    sleep 2
        check
        break
    else
    dialog --title "Uh-oh" --backtitle "$version" --yesno "I'm sorry, but $location doesn't exist. Did you mean elsewhere?" 10 60
     case $? in
            0)
             dialog --title "Directory" --backtitle "$version" --inputbox "Plese type the directory EX: '/home/root'\n\n *NOTE: Do not provide the trailing '/'" 10 60 2> /tmp/decision
             location=`cat /tmp/decision`
              case $? in
                1)
                    exit;;
                esac;;
            1)
             exit;;
      esac
    fi
   done
}
 begin
What it does, is read in a location (I've filled it in with gibberish right now for this case) and makes sure it exists. If it doesn't, it asks if you wanted to try elsewhere. Saying yes brings up another dialog box that asks you to input the directory so it can be checked again. Pressing cancel or escape at this point however always returns a 0 value to $? and tells says that a directory has been found at *blank*. Is this just my bad scripting? Or am I missing something. Thanks guys.

Note: I have looked and I am currently running the dialog package found in Slackware-current so yes I am running the latest.
 
Old 10-15-2010, 11:57 PM   #5
Guillermo Reisch
LQ Newbie
 
Registered: Mar 2010
Location: Montevideo
Distribution: Debian, Ubuntu, knoppix
Posts: 7

Rep: Reputation: 1
Thanks at the magic starts in the universe, the solucion its simple :-P

check that especific part of the code:

Quote:
Originally Posted by soppy View Post

Code:
1) dialog --title "Directory" --backtitle "$version" --inputbox "Plese type the directory EX: '/home/root'\n\n *NOTE: Do not provide the trailing '/'" 10 60 2> /tmp/decision

2) location=`cat /tmp/decision`

3) case $? in ..... bla bla bla
OK the code in 1) work great! retun 0 (if click on OK) , return 1 (click on cancel) , return 255 (if press scape) so "$?" are good set (y) :-)

lets si what do code 2) its execute a "cat" instruction and like all instruction it sets "$?" acording to the success of that instruction that actuali is "0" (because cat /tmp/decision work whitnout any problem)

so you go to 3) you check for "$?" that is ALLWAIS "0" because you reset "$?" to 0 for calling "cat" instruction.

Who to SOLVE???


1) dialog --title "Directory" --backtitle "$version" --inputbox "Plese type the directory EX: '/home/root'\n\n *NOTE: Do not provide the trailing '/'" 10 60 2> /tmp/decision

3) case $? in ..... bla bla bla

2) location=`cat /tmp/decision`


CHECK FIRST THE RETURN OF THE DIALOG FUNCTION AND AFTER THAT OBTEIN THE location variable


Saludos Guillermo
 
Old 10-16-2010, 12:28 AM   #6
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by soppy View Post
Sorry guys. I had to go to work. Here's the code in question.

Code:
function begin {
loop=0
location=/home/soppy/blah
    dialog --title "Weclome" --backtitle "$version" --msgbox "This will back-up your directory." 11 60
    while [ $loop != 1 ]; do
    if [ -d $location ]
    then
    dialog --title "YAY" --backtitle "$version" --infobox "The directory was found at $location." 10 60
    sleep 2
        check
        break
    else
    dialog --title "Uh-oh" --backtitle "$version" --yesno "I'm sorry, but $location doesn't exist. Did you mean elsewhere?" 10 60
     case $? in
            0)
             dialog --title "Directory" --backtitle "$version" --inputbox "Plese type the directory EX: '/home/root'\n\n *NOTE: Do not provide the trailing '/'" 10 60 2> /tmp/decision
             location=`cat /tmp/decision`
              case $? in
                1)
                    exit;;
                esac;;
            1)
             exit;;
      esac
    fi
   done
}
 begin
What it does, is read in a location (I've filled it in with gibberish right now for this case) and makes sure it exists. If it doesn't, it asks if you wanted to try elsewhere. Saying yes brings up another dialog box that asks you to input the directory so it can be checked again. Pressing cancel or escape at this point however always returns a 0 value to $? and tells says that a directory has been found at *blank*. Is this just my bad scripting? Or am I missing something. Thanks guys.

Note: I have looked and I am currently running the dialog package found in Slackware-current so yes I am running the latest.
He-he. You didn't test dialog exit status, you test exit status of
Code:
location=`cat /tmp/decision`
And this file is always created by previous command redirection, so...

Also, if you just tried to run
Code:
dialog --input ...; echo $?
from the command line you were able to find that dialog works as it should (or not and look for the bug in your script (or fill bugreport for dialog)
 
Old 10-16-2010, 11:21 AM   #7
soppy
Member
 
Registered: Mar 2008
Location: In your head!
Distribution: Arch Linux
Posts: 165

Original Poster
Blog Entries: 1

Rep: Reputation: 28
Haha. I knew it was something stupid like that!!! Thank you guys so much! I guess sometimes all it takes is another set of eyes to see something wrong. It works perfectly now. Thanks again!!
 
Old 10-16-2010, 03:09 PM   #8
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by soppy View Post
Haha. I knew it was something stupid like that!!! Thank you guys so much! I guess sometimes all it takes is another set of eyes to see something wrong. It works perfectly now. Thanks again!!
You are welcome
 
  


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
is it possible to have two inputbox in one dialog window in bash? FIRATYILDIRIM Programming 6 06-02-2010 04:10 AM
[SOLVED] BASH: dialog menu with descriptions worm5252 Programming 2 05-05-2010 09:02 AM
Bash Loop Dialog xlordt Programming 5 09-26-2006 09:40 AM
bash scripting: dialog --inputbox chibiace Linux - Newbie 1 11-08-2004 10:22 PM
Dynamic dialog in bash scripts AndiOliver Programming 3 04-22-2004 02:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:15 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
Open Source Consulting | Domain Registration