How to accept arguments in shell script when calling in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to accept arguments in shell script when calling in perl
# 1  
Old 12-11-2011
How to accept arguments in shell script when calling in perl

I have a shell script like this:
Code:
#!/bin/sh
$PYTHON MetarDecoder.py < ../data/mtrs/arg1/arg2

And I'm calling it with this in perl:
Code:
my $output = `./metar_parse.sh --options`;

It's successful when I put in actual values for arg1 and arg2 in the shell script, but I'd like to pass arguments from the perl script (defining them in perl script) to the shell script so I can have dynamically changing arguments depending on date/time, etc.

I've had advice that suggested writing the perl like: my $output = `./metar_parse.sh $option1 $option2`;
where option 1 and 2 would be the arguments. But how do I set up the shell script to accept these arguments and process them in the pathname?
Thanks for any help!
S

Moderator's Comments:
Mod Comment How to use code tags

Last edited by Franklin52; 12-12-2011 at 03:19 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 12-11-2011
Positional parameters.

Code:
$ cat test.sh
#!/bin/bash
echo $1 $2

Code:
$ cat test.pl
#! /usr/bin/perl
my ($opt1, $opt2) = ("option1", "option2");
my $output = system ("./test.sh $opt1 $opt2");
print "$output\n";

Code:
$ ./test.pl
option1 option2
0

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calling perl from shell script

I am calling a perl script from shell script. $ cat mah_appln_bkp_oln.ksh #!/bin/ksh . /udb/home/udbappln/.profile . /udb/home/udbappln/sqllib/db2profile Com=/udb/udbappln/utility/systemscripts/currentUMR perl $Com/backup.pl -d dbname --tsm --purgetsmcopies 21 --purgetsmlogs exit 0 ... (1 Reply)
Discussion started by: ilugopal
1 Replies

2. UNIX for Advanced & Expert Users

Calling PERL from a Korn shell script

I am currently in Afghanistan and do not have access to some of the resources I normally do back in the US. Just accessed this site and it looks promising! Hopefully you will not find my question too much of a waste of your time. I write mostly Korn Shell and PERL on Solaris systems for the... (2 Replies)
Discussion started by: mseanowen
2 Replies

3. Shell Programming and Scripting

calling a perl script with arguments from a parent perl script

I am trying to run a perl script which needs input arguments from a parent perl script, but doesn't seem to work. Appreciate your help in this regard. From parent.pl $input1=123; $input2=abc; I tried calling it with system("/usr/bin/perl child.pl $input1 $input2"); and `perl... (1 Reply)
Discussion started by: grajp002
1 Replies

4. UNIX for Dummies Questions & Answers

script unix which accept two arguments

does anyone can help me with this homework, please..I am beginner in linux and I don't how to do it :( Create a script scanner.sh which will accept two arguments: the first argument is the DNS name or the IP address of a system, or a network address or an IP range, the second argument is... (1 Reply)
Discussion started by: gennyy
1 Replies

5. Shell Programming and Scripting

ksh script that will accept arguments

Hi, I am not very skilled using ksh scripts. How do I create a ksh script that will accept arguments and use them in the script ? I need to make this: Run this command with this argument: ./mykshprogram.ksh madsen and sometimes I need to do this: Run the ksh again with 2... (3 Replies)
Discussion started by: hasselhaven
3 Replies

6. Shell Programming and Scripting

Calling perl subroutine from shell script (sh)

Hi, ive a perl script, where it has a subroutine clear() in it, and i've one shell script which runs in background, from that shell script i wanted to call subroutine which is in perl script, that's perl script is not module, just simple script. Eg: perl script <test> #!... (4 Replies)
Discussion started by: asarunkumar
4 Replies

7. Shell Programming and Scripting

Calling perl script in shell program

How to call a perl script in shell program / shell scripting. PLS HELP ME (2 Replies)
Discussion started by: hravisankar
2 Replies

8. Shell Programming and Scripting

Writing Unix script to accept arguments

Hi, This may be answered elsewhere but I wasn't entirely sure of the wording I should use to search so here we go with an attempt: I wish to make a script that will allow commands to be passed to it such as: <command> -oOPTIONS -aANOTHER -pRINT etc However I don't really know the... (3 Replies)
Discussion started by: stuaz
3 Replies

9. Shell Programming and Scripting

calling a shell script from perl

Hi all, Not sure if this is the right forum to post query regarding perl script. I have a perl script which internally calls a shell script. My problem is that the shell script should be passed command line arguments. I call a shell script from perl using: system("sript.sh"); How do... (3 Replies)
Discussion started by: gurukottur
3 Replies

10. Shell Programming and Scripting

Calling CGI Perl in Shell script [urgent]

All I want to call a perl program from my shell script. Please help me. I want to call through URL only. Like " http://www.test.com/CGI-bin/test?test=value" Please help to write this script. Thanx in advance. Thanking you Regards Deepak Xavier (0 Replies)
Discussion started by: DeepakXavier
0 Replies
Login or Register to Ask a Question