473,387 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Passing parameters to a perl file from .sh file

How to pass parameter to a perl file (say myperl.pl) from a shell file (say work.sh ) ? and how to get that parameter in perl file ? { is using my $var = @_ }.

Thanks,
Pawan Kumar
Feb 9 '07 #1
4 12286
arne
315 Expert 100+
How to pass parameter to a perl file (say myperl.pl) from a shell file (say work.sh ) ? and how to get that parameter in perl file ? { is using my $var = @_ }.

Thanks,
Pawan Kumar
Don't know if I understood the question ... you want to invoke a perl prog (say perl.pl) from a shell script (say work.sh) and a pass a var from the shell script to the perl program?

What about (work.sh)
Expand|Select|Wrap|Line Numbers
  1. #!/bin/sh
  2. VAR='whatever'
  3. perl perl.pl var
  4.  
and in perl.pl
Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl
  2. my $var = $ARGV[0];
  3. #$var should be 'whatever' now
  4.  
HTH
Feb 9 '07 #2
jkr
3
In the above sample it should read:
perl perl.pl $VAR

---------

you can do the following:

$ export VAR='whatever'

and run:
myperl.pl
[HTML]#!/usr/bin/perl -w

defined($arg=shift(@ARGV)) && print "arg: $arg\n";
print "var: $ENV{'VAR'}\n";[/HTML]
will print:
var: whatever

./myperl.pl argument
will print:
arg: argument
var: whatever
Feb 9 '07 #3
Thanks arne and jkr.

arne, You correctly got the question. I was missing perl before myperl.pl. Since in my case, .sh file will pass paramenter at every 5 minute (Automated script), I feel first method ( of arne) is more relevent ( every time just pass the parameter as argument). thank you.

jkr, from your answer, I learned a new way of doing the same thing in a different way. thanks.

Regards,
Pawan Kumar
Feb 11 '07 #4
@pawanrpandey

If the word perl in front of your command line does the trick, you probably do not have a "she-bang" line in your perl script.

If the first line of your perl script is
Expand|Select|Wrap|Line Numbers
  1. #!<path>/perl
where <path> is the path to your perl interpreter, and if the script is executable (chmod +x <script>), you do not need to put the word perl in front of your command line. You can call the script directly, instead.

Greetz, Doc
Feb 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: google_nospam | last post by:
Thanks in advance for any help. I'm looking for a way to pass data from php to perl. Basically, I want to take some dynamic data from a database, mixed with user input, then reformat it to make a...
1
by: Romuald Favre | last post by:
Hi there, I just installed Perl (v. 5.6.1. built for MSWin32 from ActiveState) on a new server Windows 2000. Amazingly the passing of arguments doesn't work ! I saved the following code in a...
1
by: Joe | last post by:
I am trying to write a Perlscript to be used with some HTML pages. Here is how it works: 1.. The first HTML page has a form which requests for user input. Then it passes the QUERY_STRING...
26
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
4
by: asearle | last post by:
Hi everyone, I have a perl script that opens an Access mdb thus: system("C:\\Documents\ and\ Settings\\asearle\\My\ Documents\\iwh_dev\\MyAccessDB.mdb"); This works absolutely fine and,...
0
by: Xah Lee | last post by:
In this article, i explain how the use of bit masks is a hack in many imperative languages. Often, a function will need to take many True/False parameters. For example, suppose i have a function...
8
by: jayakumarrt | last post by:
Dear Friends, I have a perl script abc.pl.I will be running this script with an parameter .The same parameter value i would like to pass to the shell script (The shell script is inside perl...
3
by: ajaymohank | last post by:
hello everyone..... i am ajay and i am new to php. in my project i have an option to invoke a bat file by passing parrameters and to diplay the result. i tried this code but my page got hung or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.