Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Require input in bash dialog box


    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:
    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

  2. #2
    Code:
    #!/bin/bash
    
    rfcval=`cat $rfcfile`
    while [[ "x$rfcval" == "x" ]]
    do
    
    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
    
    done
    not tested.
    How to ask smart questions | Don't be a Help Vampire
    You can post a link by removing "http://www." from it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •