Passing PERL var values to SH Shell Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing PERL var values to SH Shell Script
# 1  
Old 11-16-2012
Passing PERL var values to SH Shell Script

Greetings all,

If I have a SH script that calls a PERL script in the following way:

Code:
perl $HOME/scripts/config.properties

And in the config.properties PERL file, this Perl script only sets a number of environmental parameters in the following way:

Code:
#!/usr/bin/perl
$VAR1 = (
     'PECOSSource' => '/opt/tibco/incoming',
     'PECOSDestination' => '/opt/apsproc/implementation/TIBCO',
     'PECOSArchive' => '/opt/apsproc/tibco/archive/incoming',
     'PECOSFileName' => 'PECOS_Input_1.xml'
     ...
     'PECOSResArchive' => '/opt/apsproc/tibco/archive/outgoing');

If my SH shell script executes the config.properties PERL script, how can my SH shell script access the following PERL-defined parameters such as: PECOSSource, PECOSDestination, PECOSArchive, PECOSFileName, and PECOSResArchive?? Any further guidance would be greatly appreciated.

Thanks,

Patrick Q

Last edited by Corona688; 11-16-2012 at 06:11 PM..
# 2  
Old 11-16-2012
You can't. Variables don't work that way.

You could perhaps execute a perl script to print the values in a way the shell can understand, then source those values.
# 3  
Old 11-16-2012
Quote:
Originally Posted by gikyo12
If my SH shell script executes the config.properties PERL script, how can my SH shell script access the following PERL-defined parameters such as: PECOSSource, PECOSDestination, PECOSArchive, PECOSFileName, and PECOSResArchive?? Any further guidance would be greatly appreciated.
Try it this way and see if this is what you want:
Code:
$ cat perl1.pl
#!/usr/bin/perl
$ENV{'PECOSSource'}        =  "/opt/tibco/incoming";
$ENV{'PECOSDestination'}   =  "/opt/apsproc/implementation/TIBCO";
$ENV{'PECOSArchive'}       =  "/opt/apsproc/tibco/archive/incoming";
$ENV{'PECOSFileName'}      =  "PECOS_Input_1.xml";
$ENV{'PECOSResArchive'}    =  "/opt/apsproc/tibco/archive/outgoing";

printf( "%s %s %s %s %s\n", $ENV{'PECOSSource'}, $ENV{'PECOSDestination'}, $ENV{'PECOSArchive'}, $ENV{'PECOSFileName'}, $ENV{'PECOSResArchive'} );

$ cat shell1.sh
#!/usr/bin/ksh
perl1.pl | read PECOSSource PECOSDestination PECOSArchive PECOSFileName PECOSResArchive

echo $PECOSSource
echo $PECOSDestination
echo $PECOSArchive
echo $PECOSFileName
echo $PECOSResArchive

$ shell1.sh
/opt/tibco/incoming
/opt/apsproc/implementation/TIBCO
/opt/apsproc/tibco/archive/incoming
PECOS_Input_1.xml
/opt/apsproc/tibco/archive/outgoing

# 4  
Old 11-16-2012
Should be noted that only works in ksh, other shells will set the variables in a subshell.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing values to an XML file from shell script

:wall: Hi, I have an XML file with 5 tags. I need to pass values to the XML file from a shell script that will replace values in 2 of the tags. I cannot hardcode the tag values in XML and use replace command in script as the values are likely to change. Please help !!!!!!!!!!! (2 Replies)
Discussion started by: Monalisaa
2 Replies

2. Shell Programming and Scripting

Passing values from awk to shell variable

I am writing a script where I need awk to test if two columns are the same and shell to do something if they are or are not. Here is the code I'm working with: @ test = 0 ... test = `awk '{if($1!=$2) print 1; else print 0}' time_test.tmp` #time_test.tmp holds two values separated by a space... (3 Replies)
Discussion started by: Malavin
3 Replies

3. Shell Programming and Scripting

checking co-presence of Var. - Shell or Perl

Hey fellas, I've posted this problem a few days back and I received just one post which was in PHP that I have no idea about! (Thanks to DGPickett) It would be so nice if you can help me with this in Shell or Perl. Here is the story: I have a big table with variables and observations. I... (9 Replies)
Discussion started by: @man
9 Replies

4. Shell Programming and Scripting

passing values to the shell script

Hi, Solaris : 10 . I have 3 database in single file system i.e. /d01 . whenever I connect to oracle user using the below method #su - oracle It will prompt for which database environment you want to set(PROD,TEST,UAT) : whichever i need i will enter required DATABASE and perform my... (2 Replies)
Discussion started by: maooah
2 Replies

5. Shell Programming and Scripting

Passing a file handler and an array from Perl to Shell Script

Hi there, I am trying to call a shell script from a Perl script. here is the code: @args = ("sh", "someshellprg.sh", "a file handler", "an array"); system(@args) == 0 or die "system @args failed: $?"; in the shell program, I examine if the arguments exits using: if then echo... (5 Replies)
Discussion started by: pinkgladiator
5 Replies

6. UNIX for Advanced & Expert Users

Passing the values to the secondary script when it invoked by primary script

Hi, When I invoke a script s1.sh it will call an another script s2.sh by itself. This script s2.sh will call some java files, so while running the script it asks for a file name to be processed. Which we can see in the screen. The file name to be processed is present in script s1.sh Now I... (2 Replies)
Discussion started by: venu_eie
2 Replies

7. Shell Programming and Scripting

passing values from sql to shell script

Hi guyz, Posting a thread after a long time. I want to pass two variables to unix shell script from sql script. Note: I am calling sql script from unix script. sql script has 2 variables one is the return code for status of program run and second one email flag. I don't know how to capture... (3 Replies)
Discussion started by: sachin.gangadha
3 Replies

8. Shell Programming and Scripting

Need help passing variables in shell script to perl one-liner

I'm writing a script to automate some post-install tasks on RHEL4 servers. I need the following code to insert an 'A' in the middle of a string, then replace the string in a file. I know I can use sed to do this, but I'd like to use perl's in place edit so I don't have to write to a temp file,... (1 Reply)
Discussion started by: Xek
1 Replies

9. Shell Programming and Scripting

Passing Values from a shell script

Hi all I want to know how to pass value from one shell script to another suppose i have script named A.This 'A.sh' calls 'B.sh' .Now some calculations are done by B.sh ..Say in variable X. Now i want to pass the value of this X variable to 'A.sh'... A.sh ----> B.sh ( X variable ) ... (6 Replies)
Discussion started by: dhananjaysk
6 Replies

10. Programming

Passing Parameters and getting values back from a c program to Shell script

I am having a shell script which has to be called from a C program. I have to pass two parameters to this script. HOw can I do that? eg: int main() { char st1; char str2; // call a shell script call_sh(str1,str2) where call_sh is the name of the shell script. then i need to get the return... (5 Replies)
Discussion started by: Rajeshsu
5 Replies
Login or Register to Ask a Question