Sponsored Content
Top Forums Shell Programming and Scripting Require input in bash dialog box Post 302994071 by drysdalk on Saturday 18th of March 2017 11:30:04 AM
Old 03-18-2017
EDIT: First version didn't do the input loop, sorry - fixed now.

----------
Hi,

Would something like this do the trick for you ?

Code:
#!/bin/bash
validinput=0

while [ "$validinput" != "1" ]
do
        echo "Please enter an RFC number"
        read rfcnumber

        case $rfcnumber in
                "")
                        echo Either type in your RFC number, or enter N/A if one is unavailable.
                        ;;
                N/A)
                        echo You have indicated an RFC number is not available.
                        validinput=1
                        ;;
                *)
                        if echo "$rfcnumber" | /bin/grep -E "^[0-9]{5,}$" >/dev/null 2>/dev/null
                        then
                                echo Valid RFC number entered.
                                validinput=1
                        else
                                echo "Invalid RFC number entered"
                                echo "Please enter a minimum of five digits only, or N/A if you don't have one"
                        fi
                        ;;
        esac
done

echo "You provided the following valid input:"
echo $rfcnumber

(You could keep using dialog here, I just used the builtin read for my own convenience when writing this).

Here's a sample session, showing it ony accepting input that conists of solely digits, and a minimum of five of them. It will keep prompting the user to enter an RFC until a valid one is provided.

Code:
$ ./script.sh
Please enter an RFC number

Either type in your RFC number, or enter N/A if one is unavailable.
Please enter an RFC number
N/A
You have indicated an RFC number is not available.
You provided the following valid input:
N/A
$ ./script.sh
Please enter an RFC number
123
Invalid RFC number entered
Please enter a minimum of five digits only, or N/A if you don't have one
Please enter an RFC number
ABC
Invalid RFC number entered
Please enter a minimum of five digits only, or N/A if you don't have one
Please enter an RFC number
a12345
Invalid RFC number entered
Please enter a minimum of five digits only, or N/A if you don't have one
Please enter an RFC number
12345a
Invalid RFC number entered
Please enter a minimum of five digits only, or N/A if you don't have one
Please enter an RFC number
1234-567
Invalid RFC number entered
Please enter a minimum of five digits only, or N/A if you don't have one
Please enter an RFC number
123456
Valid RFC number entered.
You provided the following valid input:
123456

Hope this helps. If this isn't quite right let me know and I'll see if I can tweak it.

Last edited by drysdalk; 03-18-2017 at 12:37 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Displaying a dialog box using terminal commands

Hello, I used the command osascript -e 'tell app "Finder" to display dialog "Hey!"' to display a dialog box..it works fine, it displays a dialog box with 'OK' and 'CANCEL' buttons..i want to get the button returned value how can i do that using terminal command? is there any command to get... (1 Reply)
Discussion started by: keshav.murthy@r
1 Replies

2. Shell Programming and Scripting

Pop up dialog box on remote computers

I need to send out messages to over 100 clients in my sector. I want it to pop up a dialog box letting them know to save work and log out. I have the reboot script created just need the warning please. Thanks (35 Replies)
Discussion started by: deaconf19
35 Replies

3. Shell Programming and Scripting

Unix / Linux Dialog Utility - how to open 2+ more dialog windows ?

Hi, example of Unix / Linux dialog utility is below. I am going to use dialog as simple GUI for testing of a modem. So I need to combine some dialog boxes into one. I need to have input box, output box, info box, dialog box, radiobox as in any standard program with graphical user... (2 Replies)
Discussion started by: jack2
2 Replies

4. Debian

Dialog box in debconf file.

Hi all, I am working with debconf file for packaging the projects. I have used the ". /usr/share/debconf/confmodule" file to do the packaging in debian standard. It worked fine. When ever I am installing the package in apt-get the dialogs are come as I mentioned in the templates file.... (0 Replies)
Discussion started by: Nila
0 Replies

5. Shell Programming and Scripting

Script to display a dialog box every 5 seconds

I want to create a script that displays a dialog box every interval of time and exits that loop when a user presses ENTER Any idies? (4 Replies)
Discussion started by: amitlib
4 Replies

6. Red Hat

Authentication Failed Dialog Box on Redhat 4.7

For some reason i cannot login using root or other accounts on my Linux system. When logging in at the main console it says "Authentication failed" in a dialog box with an OK button. The Linux system is Redhat 4.7. I've already checked /etc/pam.d/login, /etc/security/access.conf and ... (27 Replies)
Discussion started by: redhatuser2012
27 Replies

7. Shell Programming and Scripting

How to create multiple input box in same window using dialog

Hi All, I was trying to generate GUI using shell script. After long search I found the utility called “dialog”. Using this utility I am able to generate window to collect the input. dialog --inputbox "Input 1" 10 45 dialog --inputbox "Input 2" 10 45 dialog --inputbox "Input 3" 10 45 Using... (2 Replies)
Discussion started by: kalpeer
2 Replies

8. UNIX for Dummies Questions & Answers

Dialog box

I know, I can run dialog command in my machine. But what I want to do is I wanna show the dialog box to some other Remote host. I connected to the remote system and used dialog command its shows the box in my terminal only. How can I display to that remote machine?? Any suggestions??? (3 Replies)
Discussion started by: Adhi
3 Replies

9. Shell Programming and Scripting

Dialog box in korn shell scripting

Does dialog box works on all kind of shells? I am using korn shell in Linux . For me dialog is not working :) is there any particular syntax or do we need to have particular OS version or shell env? #!/bin/ksh dialog --title "create file" \ --backtitle "shell script practice" \... (1 Reply)
Discussion started by: NarayanaPrakash
1 Replies

10. Shell Programming and Scripting

Dynamic Bash Dialog from directory listing

Hey! I want to get a directory listing and turn it into a bash dialog menu. I need to append information from the files themselves (they'll be text files) onto the actual filenames as well. I want to feed the appended filename list into the dialog menu as options. I need to make a case... (5 Replies)
Discussion started by: shrout1
5 Replies
lmfsetup(8)						      System Manager's Manual						       lmfsetup(8)

Name
       lmfsetup - License Management Facility PAK registration script

Syntax
       /etc/lmfsetup [ template ]

Description
       The  script allows you to register data supplied by a Product Authorization Key (PAK).  The script prompts you for the data associated with
       each of the fields on a PAK.  When all the data has been entered, the License Management Facility (LMF) ensures there are  entries  against
       all  the mandatory fields, and that the Checksum validates all the license data.  If the data has been entered correctly, the PAK is regis-
       tered in the License Database.  If the data has been entered incorrectly, the appropriate error message is displayed and you are given  the
       opportunity to re-enter the data.

       The template option allows you to register license data from templates in A template containing a partially complete PAK is created by some
       products as part of their installation process.	The script only prompts you for data on the fields that are empty in the template.  If the
       script cannot find the specified template in it searches the current directory.

       The  script  is	provided as an alternative to the command.  This displays a template, which includes the fields on the PAK, and invokes an
       editor so that you can add the license data to the appropriate field.  The command also allows errors to be corrected without having to re-
       enter all the data.

See Also
       lmf(8)
       Guide to Software Licensing

																       lmfsetup(8)
All times are GMT -4. The time now is 08:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy