Hi,
I need to get input arguments, as well as validate them. This is how I'm reading them:
My problem is how validate incompatible arguments. For instance, it's not allowed to call script with both "-z" and "-b", or "-n" and "-z", and so on.
I stored input arguments into a variable called "args" (because shift command unsets them).
Is there a simple way to validate other than a double loop? This is what occurred to me, but is really ugly. Any hint to improve?
Thanks and sorry for my english
It's not what I expected, but it's a nice and simple solution. Did not know why it didn't occur to me... I was stubborn in use an "args" variable, that I didn't realize there was a much simpler solution
The solution of Corona will indeed work, but i think there is an even more "correct" solution to this: use the getopts keyword of your shell or the /usr/bin/getopts executable respectively.
getopts provides (basic) error handling and essentially does what you want to achieve, plus it understands the common UNIX-syntax: if you have "/some/command" and want to pass it two options, "x" and "y" you would write:
rather than
Corona688s way of parsing the commandline would require the latter instead of the former. You might read the man page of getopts and ask again if you have any additional questions about its usage.
Here is a (very basic) example of how to use it: suppose you have 2 legal options, "-a" and "-b", of which one takes an additional argument:
We have a job which we need to run on daily bases, before loading data in a table we need to validate whether the input file is received or not.Inputfile formatsrc_sps_d_Call_Center_Reporting_yyyymmdd_01.dat SPS-Service nameYYYY-yearMM-MonthDD-dayLike above we will get n number of files for... (1 Reply)
$Input_filename=$ARGV;
if (!-d $Input_filename && ! -e $Input_filename)
{
print "USAGE: Please enter '$ABCD/def/dsed.txt' as an arguement \n";
exit;
}
1. Input Is suppose to be something like "$ABCD/def/dsed.txt".
if the input is wrong the script should throw an ERROR message.... (2 Replies)
Is there an easy way to validate an input field size. Let us say a script is asking to enter 10 digits mobile number, how do I write a script to validate it is numeric and is 10 digits in length? I just need an easy way w/o using looks ...etc. Is there such a away ?
Here is what I have so far... (6 Replies)
I'm writing a bash shell script to 'help' me post to susepaste (I can NEVER remember the time options).
Here's the code:
#!/bin/bash
##########
#
# Project : personal script.
# Started : Wed Aug 03, 2011
# Author : Habitual
# Description : susepaste c-li script with user... (5 Replies)
The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Hi,
This will most likely be a simple answer.
Currently I have a situation where my script will be sent various options:
-o1 -o2 -oe3@somthing.com
Now, if I want to run a certain command based on the option I am sent, I am doing the following.
for o in $(echo $options)
do
if
... (3 Replies)
the user inputs names that have to be inside square brackets
I want to check if the user puts the brackets and if not ask him to re-enter the names (9 Replies)
Hi all,
I have a shell script(K shell) which takes a date as input.
i want the input to be in DD-MM-YYYY format.
Can i enforce such a format of input string using just one line of code?
OR
do i need to parse the input date into different components and test them using Case statements... (2 Replies)