04-06-2011
getopts :- expecting required input format
The requirement is, i'm using getopts for calling two different function depending upon the input the user gives. Two functions are
1. help
2. processing function
these two functions are written inside the script and if the user gives only the below format the processing function should be called else only help function need to be called.
syntax format : sh script <YYYY-MM-DD-HH> <number>
format : sh scriptname.sh 2011-03-04-00<space-separated>6
please help me out with getopts code how it should be.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I want the user to enter only numeric values and also he should only enter
2 digits only ( eg 23 or 23 or 03 any 2 digits)
For the above purpose how should i declare my variable ?
integer value
if I read 03 in variable value then it gives me error ...also user can enter n number... (4 Replies)
Discussion started by: dhananjayk
4 Replies
2. UNIX for Advanced & Expert Users
Hello,
I need to change user and run some commands by using a script.
lets say, I'm using
su - someuser << start
password required -----> how can I enter the password here
command 1
command 2
command 3
command 4
start
While trying to run this I got the following message:
"standard... (2 Replies)
Discussion started by: Alalush
2 Replies
3. Shell Programming and Scripting
I have a script which takes user input as options provided
PS3="Select option to do deploy : "
select OPTION in "eardeploy" "hotdeploy"
do
case $OPTION in
"eardeploy" )
eardeploy.sh
break;;
"hotdeploy" )
... (1 Reply)
Discussion started by: codeman007
1 Replies
4. Shell Programming and Scripting
Guru,
I am trying to use telnet in unix script.
And it's asking password after executing telnet command in script.
But I don't want to have manual intervention over there.
So is it possible to pass password for telnet from script itself.
What I am doing right now is something like this.
... (4 Replies)
Discussion started by: gander_ss
4 Replies
5. Shell Programming and Scripting
I have this file
103,7243534512111,NiaC1-02
105,720412845543550,NiaC2-00
105,720439254543351,NiaC200
105,720445724354315,Nia100
105,72044770454398,Nia100
105,720484154334546,Nia616
i want in this format
insert into aildump values(103,'7243534512111','NiaC1-02');
I'm able to... (3 Replies)
Discussion started by: nikhil jain
3 Replies
6. Shell Programming and Scripting
Firstly one of my mysql queries will yeild following output
+-------+---------------------+-------------------+----------------------------------------------------------------------------+
| ID | PLATFORM | SORT_NAME | DESCRIPTION ... (2 Replies)
Discussion started by: vivek d r
2 Replies
7. Shell Programming and Scripting
Hello Everyone,
I have one source file which is genarated by SAP in different format(Which I've never seen). I need to convert that file to required format and I need to read this target file from Datastage to use this in my Jobs. So I do not have any other options except to use Unix script to... (4 Replies)
Discussion started by: Prathyu
4 Replies
8. UNIX for Dummies Questions & Answers
My file format:
--------------------------------------------------
Complete Consistency Check
Valid Area : VALID:VALID
Started by : esanwad
Started at : Thu Dec 11 16:04:46 2014
CNA version : R21H04_EC08
Check range : AREA VALID/VALID
... (4 Replies)
Discussion started by: Gautam Banerjee
4 Replies
9. Post Here to Contact Site Administrators and Moderators
We have been told to use this method for contacting moderators (rather than PM).
Can any moderator please checkout what member 'buyvpn' is up to.
Thanks.
---------- Post updated at 11:19 AM ---------- Previous update was at 11:15 AM ----------
Advertising services on at least one post. (1 Reply)
Discussion started by: hicksd8
1 Replies
10. Shell Programming and Scripting
Hi All,
I 'm matching two files based on the first 2 columns and then populate other fields along with subtraction of few fields.
I have managed to get the output. However, is there a easier way in formatting the output as shown below instead of using additional printf for getting fixed width... (4 Replies)
Discussion started by: shash
4 Replies
LEARN ABOUT DEBIAN
getopt::std
Getopt::Std(3perl) Perl Programmers Reference Guide Getopt::Std(3perl)
NAME
getopt, getopts - Process single-character switches with switch clustering
SYNOPSIS
use Getopt::Std;
getopt('oDI'); # -o, -D & -I take arg. Sets $opt_* as a side effect.
getopt('oDI', \%opts); # -o, -D & -I take arg. Values in %opts
getopts('oif:'); # -o & -i are boolean flags, -f takes an argument
# Sets $opt_* as a side effect.
getopts('oif:', \%opts); # options as above. Values in %opts
DESCRIPTION
The getopt() function processes single-character switches with switch clustering. Pass one argument which is a string containing all
switches that take an argument. For each switch found, sets $opt_x (where x is the switch name) to the value of the argument if an
argument is expected, or 1 otherwise. Switches which take an argument don't care whether there is a space between the switch and the
argument.
The getopts() function is similar, but you should pass to it the list of all switches to be recognized. If unspecified switches are found
on the command-line, the user will be warned that an unknown option was given. The getopts() function returns true unless an invalid
option was found.
Note that, if your code is running under the recommended "use strict 'vars'" pragma, you will need to declare these package variables with
"our":
our($opt_x, $opt_y);
For those of you who don't like additional global variables being created, getopt() and getopts() will also accept a hash reference as an
optional second argument. Hash keys will be x (where x is the switch name) with key values the value of the argument or 1 if no argument
is specified.
To allow programs to process arguments that look like switches, but aren't, both functions will stop processing switches when they see the
argument "--". The "--" will be removed from @ARGV.
"--help" and "--version"
If "-" is not a recognized switch letter, getopts() supports arguments "--help" and "--version". If "main::HELP_MESSAGE()" and/or
"main::VERSION_MESSAGE()" are defined, they are called; the arguments are the output file handle, the name of option-processing package,
its version, and the switches string. If the subroutines are not defined, an attempt is made to generate intelligent messages; for best
results, define $main::VERSION.
If embedded documentation (in pod format, see perlpod) is detected in the script, "--help" will also show how to access the documentation.
Note that due to excessive paranoia, if $Getopt::Std::STANDARD_HELP_VERSION isn't true (the default is false), then the messages are
printed on STDERR, and the processing continues after the messages are printed. This being the opposite of the standard-conforming
behaviour, it is strongly recommended to set $Getopt::Std::STANDARD_HELP_VERSION to true.
One can change the output file handle of the messages by setting $Getopt::Std::OUTPUT_HELP_VERSION. One can print the messages of "--help"
(without the "Usage:" line) and "--version" by calling functions help_mess() and version_mess() with the switches string as an argument.
perl v5.14.2 2010-12-30 Getopt::Std(3perl)