Other Require user input in bash "dialog" input box

woodson2

Member


Messages: 36

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
 

aragats

Daemon

Reaction score: 766
Messages: 1,664

I would use sed(1), e.g. the following will print only the patterns you want:
Code:
echo $retval | sed -n '/^[0-9]\{5,\}$/p ; /^[nN]\/[aA]$/p'
 

Eric A. Borisch

Aspiring Daemon

Reaction score: 388
Messages: 615

echo > "$rfcfile"

while ! egrep -qi '^(n/a|[0-9]{5,})$' "$rfcfile"; do
# commands updating rfcfile go here
done
 
Top