Sponsored Content
Top Forums Shell Programming and Scripting Valid input compared with input Post 302437530 by durden_tyler on Thursday 15th of July 2010 09:52:24 AM
Old 07-15-2010
Quote:
Originally Posted by ckozler
...
In short, I want to validate a users input in comparison with what I dictate as valid options-- the current logic I have tried time and time again does not seem to work as expected because it is simply doing a not equal check which occasionally fails because it is still hitting a valid option BUT just because the two strings do not equal each other, it errors out. This is not what I want.
...

You have the @selections array. And you have the @valid_options array. What you want to do is - loop through @selections array, and use grep to check if the current element is present in @valid_options array. If it is, you have a valid option; otherwise not.

Code:
$
$
$ perl -le '@valid_options = qw(valid1 valid2); @selections = qw(valid1 valid2 valid3 valid4);
            for $i (@selections) {print "$i is ", grep(/$i/,@valid_options) ? "Valid!" : "Invalid!"}'
valid1 is Valid!
valid2 is Valid!
valid3 is Invalid!
valid4 is Invalid!
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to prompt for input & accept input in ONE line

hi, am a new learner to shell programming. i have a script which will prompt for user to key in their name & display their name afterwards. script ===== echo "Pls enter your name:" read name echo "Your name is $name." output ===== Pls enter your name: Bob Your name is Bob. what... (2 Replies)
Discussion started by: newbie168
2 Replies

2. Shell Programming and Scripting

How to check for a valid numeric input

Hi Folks, I'm using bash script. I would like to check whether input is a number or not.(Only positive numbers).. if space or non numeric is entered, it should say "invalid input". pls help.. thanks in adv. Br/// Vijay. (1 Reply)
Discussion started by: Vijayakumarpc
1 Replies

3. Shell Programming and Scripting

Reading specific contents from 1 input files and appending it to another input file

Hi guys, I am new to AWK and unix scripting. Please see below my problem and let me know if anyone you can help. I have 2 input files (example given below) Input file 2 is a standard file (it will not change) and we have to get the name (second column after comma) from it and append it... (5 Replies)
Discussion started by: sksahu
5 Replies

4. Shell Programming and Scripting

Problems with valid input

Hello all I am having problems with a part of my script. Basically it asks for the user to enter a new id number for them. The catches are:- * It cannot already be existing (it will check a file) * It has to be four characters * It can only be numbers * It cannot call back into the... (2 Replies)
Discussion started by: ChrisHoogie
2 Replies

5. Shell Programming and Scripting

Validating uppercase/lowercase of user input with perl compared to unix folders

Hi, I need to copy files from a source directory to a destination directory in unix. I'm using the file::copy for the actual copy. The problem is that the source and dest directories are supplied by different users, who might type the name of the directories in various combinations of lower... (6 Replies)
Discussion started by: Furou
6 Replies

6. Shell Programming and Scripting

How to get the user input recursively until the user provides valid input

Hi, echo "Enter file name of input file list along with absolute path : " read inputFileList if then for string in `cat inputFileList` do echo $string done else echo " file does not exist" fi From the above code, if the user enters a invalid file... (1 Reply)
Discussion started by: i.srini89
1 Replies

7. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

8. Shell Programming and Scripting

function terminating if i give input as space or no input and enter

HI i have written a script to ask input from the user. this script should promote the user for y/n input. if user enters anyother input then y/n the script promotes him again. this below code is working fine for all the cases. except for space and enter " if i give space and enter it is... (2 Replies)
Discussion started by: BHASKARREDDY006
2 Replies

9. Shell Programming and Scripting

How to check the user input to be valid using shell script?

How to check the user input to be valid using shell script? The valid input is in the format like as follows. 1. It can only have r,w,x or a hyphen and nothing else. 2. ensure the r, w, x are in the correct order. for example: rwxr-xr-x is a valid format. Thanks (5 Replies)
Discussion started by: hyeewang
5 Replies

10. Shell Programming and Scripting

Read input files and merge them in given order and write them to input one param or one file

Dear Friends, I am looking for a shell script to merge input files into one file .. here is my idea: 1st paramter would be outfile file (all input files content) read all input files and merge them to input param 1 ex: if I pass 6 file names to the script then 1st file name as output file... (4 Replies)
Discussion started by: hyd1234
4 Replies
gfx_mode_select(3alleg4)					  Allegro manual					  gfx_mode_select(3alleg4)

NAME
gfx_mode_select - Displays the Allegro graphics mode selection dialog. SYNOPSIS
#include <allegro.h> int gfx_mode_select(int *card, int *w, int *h); DESCRIPTION
Displays the Allegro graphics mode selection dialog, which allows the user to select a screen mode and graphics card. The initial values at the addresses provided by card, w, and h are used as the default selections in the dialog if they are found in the driver and mode lists. If they are not found then the initial selections will be the first in each list. If you wish to ensure that the initial selection is always the first entry, then initialize the data at the addresses passed to the function to the value of 0 or -1. If the dialog is OK'd, it stores the selections at the addresses passed to the function. RETURN VALUE
See the gfx_mode_select_filter function for the return values. SEE ALSO
gfx_mode_select_ex(3alleg4), gfx_mode_select_filter(3alleg4), set_gfx_mode(3alleg4), gui_fg_color(3alleg4) Allegro version 4.4.2 gfx_mode_select(3alleg4)
All times are GMT -4. The time now is 05:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy