Problem with Getopt

A

Arvind Kumar

Hi Guys,
I am summarizing this problem with a example. Appreciate if someone
could help me.

Say, I have a wrapper shell script which calls a perl program. I want
to pass the command line options to this perl program.

In the Wrapper (TCSH) script, I have something like this
set TEMP = "x y z";
mytest.pl -t ${TEMP};
------------------------
In the Perl program, I have something like this;
(Only fragment shown)
my $status = GetOpt::Long:GetOptions ('t|test=s' => \$temp_var);
print "$temp_var \n";
---------------
This prints only x and not all of the "x y z"
I am new to Perl but reasonably good in scripting.. Please help me..

Regards,
Arvind Kumar
 
J

Jim Gibson

Arvind said:
Hi Guys,
I am summarizing this problem with a example. Appreciate if someone
could help me.

Say, I have a wrapper shell script which calls a perl program. I want
to pass the command line options to this perl program.

In the Wrapper (TCSH) script, I have something like this
set TEMP = "x y z";
mytest.pl -t ${TEMP};

This is equivalent to the command line: 'mytest.pl -t x y z'
Thus, 'x' is the value of the -t parameter. 'y' and 'z' are ignored by
the '-t' option according to the normal syntax of command line options.

It's spelled 'Getopt' on my system!
print "$temp_var \n";
---------------
This prints only x and not all of the "x y z"
I am new to Perl but reasonably good in scripting.. Please help me..

Regards,
Arvind Kumar

Your program is behaving normally. If you want to enter 'y' and 'z' as
some type of command line option, you must tell Getopt about the
additional options. If you really want to enter "x y z" as the
parameter for the -t option, put it in quotes: mytest.pl -t "x y z"
In your shell script, you need to do:

mytest.pl -t "${TEMP}"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top