Require input in bash dialog box

Need help with C, C++, perl, python, etc?

Require input in bash dialog box

Postby woodson2 » 2017-03-18 14:30

Hello.

Any help would be greatly appreciated.

Right now I have the following input box that works fine and well, however I would like to wrap this is a loop that requires input. Right now the script will happily continue on if the user just hits enter. I'd like to require a minimum of a 5 digit number or n/a or N/A as the only viable options otherwise you should get prompted to re-enter information.

Code: Select all

DIALOG=${DIALOG=dialog}
$DIALOG --title "RFC NUMBER" --clear \
        --inputbox "Please enter an RFC Number" 16 17 2> $rfcfile

retval=$?
rfcval=`cat $rfcfile`

case $retval in
  0)
    echo RFC Number: "$rfcval" >> $accessfile;;
  1)
    exit 1;;
  255)
    rm -rf $accessfile && rm -rf $tempfile && rm -rf $rfcfile && rm -rf $sitefile && exit 1;;
  esac

woodson2
 
Posts: 3
Joined: 2012-11-27 19:50

Re: Require input in bash dialog box

Postby dasein » 2017-03-18 16:11

Maybe I'm missing something, but it sounds like you already have your solution. You know that you need to use a loop, and you know the condition(s) that should cause your loop to end.

If you're imagining that you're still missing "a piece," the only thing I can think of is the (optional) use of a "flag" variable to signal success/failure. What else do you imagine that you'd need?
User avatar
dasein
 
Posts: 7775
Joined: 2011-03-04 01:06
Location: Terra Incantationum

Re: Require input in bash dialog box

Postby debiman » 2017-03-18 18:21

can't dialog be told to not accept empty input, i.e. to force the user to input an actual string and not just enter?
User avatar
debiman
 
Posts: 1202
Joined: 2013-03-12 07:18

Re: Require input in bash dialog box

Postby phenest » 2017-03-18 18:40

Maybe it would be better if you check the input to see if it's a 5 digit number, and if not, break with an error, and don't use a loop.
NEC Spirit 550 P4 3.8GHz HT - 2GB RAM - nVidia 7600GT - Pioneer BDR-209DBK
ASUS Sabertooth P67 i7 3770K - 32GB RAM - 2x nVidia 660GTX SLI'd
User avatar
phenest
 
Posts: 1571
Joined: 2010-03-09 09:38
Location: The Matrix


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

fashionable