Using variable from shell script in perl file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using variable from shell script in perl file
# 1  
Old 05-29-2013
Using variable from shell script in perl file

Hey,

So I have a shell script that outputs some variables, call them $a and $b. I know in shell scripting if I wanted to use the variables in another shell script I'd do
Code:
sh code.sh "$a" "$b"

How can I do something similar with perl?
# 2  
Old 05-30-2013
A shell script can print variables, name and value or just values
or if dotted in the same shell (sourced) can set (exported or not) variable values to the environment of the current shell, since that is what runs the script, not a child shell process.

A PERL program can print the variables so a wrapper, parent shell can capture and export them "export `perl_prog.pl`"
or can call a shell or shell script as a child (`shell_script.sh`, system(), popen()), which will inherit the PERL environment, with any environment changes PERL made (How do I set environment variables in Perl programs? | Perl ENV array | alvinalexander.com).
# 3  
Old 05-31-2013
Quote:
Originally Posted by viored
How can I do something similar with perl?
If I understand your question, This is a real simple example:
Code:
$ cat p1.pl
#!/usr/bin/perl -w
# Script:  p1.pl
print "I am p1.pl\n";
my $v1  =  "param1";
my $v2  =  "param2";
system( "perl p2.pl $v1 $v2" );

$ cat p2.pl
#!/usr/bin/perl -w
# Script:  p2.pl
print "I am p2.pl, with: $ARGV[0], $ARGV[1]\n";


$ p1.pl
I am p1.pl
I am p2.pl, with: param1, param2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

Error while reading variable from a file in perl script

I have a file abc.ini and declared many variables in that file, one of the variable(DBname) value I am trying to read in my perl script but getting error. File abc.ini content # database name DBname =UATBOX my $ex_stat; my $cmd_output; $ex_stat = "\Qawk '/^DBname/{print... (2 Replies)
Discussion started by: Devesh5683
2 Replies

3. Shell Programming and Scripting

Change value in a file using perl or shell script

hi, I have a local.conf file which has the first line TOPDIR = "/home/mvdev/workspace/boxer". I want to replace the value to "/home/common/workspace/mirror". I tried the following perl command that is perl -p -i -e 's/Path/path1/g' myfile.txt then sed... (7 Replies)
Discussion started by: amvarma77
7 Replies

4. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

5. Shell Programming and Scripting

How to access variable from one file to another in shell script?

Hi, I had written shell script to access config file as input parameter. Contents of ConfFile.cfg are USER=ora PASSWORD=ora Shell script is DBConnect.ksh #!/bin/sh usage="`basename $0` <configuration_file_name>" DB_Connect() { sqlplus -s ora/ora << EOF CREATE TABLE TBL1... (10 Replies)
Discussion started by: Poonamol
10 Replies

6. Shell Programming and Scripting

How to return a value of a variable from shell script to perl script

HI , Is there any way to return a value of variable from shell to perl script. Code: === Perl file my $diff1=system("sh diff.sh"); my $diff2=system("sh diff1.sh"); I need exit status of below commands i.e 0 and 1 respectively. Since in both the cases diff is working so system... (3 Replies)
Discussion started by: srkelect
3 Replies

7. Shell Programming and Scripting

Perl script variable to read shell command

Solaris 10 Korn shell ksh, Hi there, I have figured out to get yesterday's date which is using the below command: TZ=GMT+24; date +%d-%b-%Y to get the format of 30-Sep-2008 and TZ=GMT+24; date +%Y%m%d to get the format of 20080930. I need this two format. In my perl script below I need... (4 Replies)
Discussion started by: bulkbiz
4 Replies

8. Shell Programming and Scripting

Shell script to read file into variable

the script i am trying to write will allow my server to give itself an ip address. So far i am up to the following but i'm stuck. tracert -m 1 > traceroute.txt 1 routername (ipaddr) 2.094 ms 1.789 ms 1.243 ms i want to get ipaddr as a variable and use it to write the ifcfg-eth... (7 Replies)
Discussion started by: aspect_p
7 Replies

9. UNIX for Dummies Questions & Answers

accessing shell script variable in file

Hi, I have a shell script in which there is a file conn_$temp where $temp has the pid of the shell script. in this shell script i have an embedded awk script that must read the file while ((getline < "conn_$temp") > 0) However due to the "$temp" in the file name, the awk script is... (6 Replies)
Discussion started by: HIMANI
6 Replies

10. Shell Programming and Scripting

Read variable from file in a C shell script

Hi, I have a 1-line file which looks like " First second third 4 five". I need to extract the number (here 4) in that line and put it in a variable. I will use the variable later to make few tests in my C shell script. Can somebody help me? (2 Replies)
Discussion started by: haouesse
2 Replies
Login or Register to Ask a Question