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
XSEL(1x)																  XSEL(1x)

NAME
xsel - manipulate the X selection. SYNOPSIS
xsel [OPTION]... DESCRIPTION
Retrieve and set the X selection. The X server maintains three selections, called PRIMARY, SECONDARY and CLIPBOARD. The PRIMARY selection is conventionally used to implement copying and pasting via the middle mouse button. The SECONDARY and CLIPBOARD selections are less frequently used by application programs. This program operates on the PRIMARY selection unless otherwise specified. By default, this program outputs the selection without modification if both standard input and standard output are terminals (ttys). Other- wise, the current selection is output if standard output is not a terminal (tty), and the selection is set from standard input if standard input is not a terminal (tty). If any input or output options are given then the program behaves only in the requested mode. If both input and output is required then the previous selection is output before being replaced by the contents of standard input. Input options -a, --append append standard input to the selection. Implies -i. -f, --follow append to selection as standard input grows. Implies -i. -i, --input read standard input into the selection. Output options -o, --output write the selection to standard output. Action options -c, --clear clear the selection. Overrides all input options. -d, --delete Request that the current selection be deleted. This not only clears the selection, but also requests to the program in which the selection resides that the selected contents be deleted. Overrides all input options. Selection options -p, --primary operate on the PRIMARY selection (default). -s, --secondary operate on the SECONDARY selection. -b, --clipboard operate on the CLIPBOARD selection. -k, --keep Do not modify the selections, but make the PRIMARY and SECONDARY selections persist even after the programs they were selected in exit. (Conventionally, the CLIPBOARD selection is persisted by a separate special purpose program such as xclipboard(1)). Ignores all input and output options. -x, --exchange exchange the PRIMARY and SECONDARY selections. Ignores all input and output options. X options -d displayname, --display displayname specify the server to use; see X(1). -t ms, --selectionTimeout ms Specify the timeout in milliseconds within which the selection must be retrieved. A value of 0 (zero) specifies no timeout (default). Miscellaneous options -l filename, --logfile filename Specify the file to log errors to when detached. (Default $HOME/.xsel.log) -n, --nodetach Do not detach from the controlling terminal. Without this option, xsel will fork to become a background process in input, exchange and keep modes. -h, --help display usage information and exit -v, --verbose Print informative messages. Additional instances of -v raise the debugging level, ie. print more information. --version output version information and exit NOTES
There is no X selection buffer. The selection mechanism in X11 is an interclient communication mediated by the X server each time any pro- gram wishes to know the selection contents, eg. to perform a middle mouse button paste. In order to implement modification of the selec- tion(s) (in input, keep and exchange modes) this program detaches from the terminal, spawning a child process to supply the new selec- tion(s) on demand. This child exits immediately when any other program takes over the selection(s), eg. when the user next selects some text in a terminal window or by running xsel -c. STANDARDS
xsel conforms to the Inter-Client Communication Conventions Manual Version 2.0 (ICCCM2). SEE ALSO
X(7), Xserver(1), xset(1), xclipboard(1), xpaste(1) AUTHOR
Conrad Parker <conrad@vergenet.net>, July 2001 January 2008 XSEL(1x)
All times are GMT -4. The time now is 05:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy