# Passing PERL var values to SH Shell Script

**URL:** <https://community.unix.com/t/passing-perl-var-values-to-sh-shell-script/319982>\
**Category:** Shell Programming and Scripting\
**Created:** [November 16, 2012, 5:04pm UTC](https://community.unix.com/t/passing-perl-var-values-to-sh-shell-script/319982 "2012-11-16T17:04:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gikyo12](https://community.unix.com/letter_avatar/gikyo12/32/5_5575768a8748004e209b776fc1b2916d.png) [@gikyo12](https://community.unix.com/u/gikyo12)\
**Post date:** [November 16, 2012, 5:04pm UTC](https://community.unix.com/t/passing-perl-var-values-to-sh-shell-script/319982/1 "2012-11-16T17:04:10Z")

</div>

Greetings all,

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

```

```nohighlight
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:

```nohighlight
#!/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

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [November 16, 2012, 5:13pm UTC](https://community.unix.com/t/passing-perl-var-values-to-sh-shell-script/319982/2 "2012-11-16T17:13:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![spacebar](https://community.unix.com/user_avatar/community.unix.com/spacebar/32/1679_2.png) [@spacebar](https://community.unix.com/u/spacebar)\
**Post date:** [November 16, 2012, 6:09pm UTC](https://community.unix.com/t/passing-perl-var-values-to-sh-shell-script/319982/3 "2012-11-16T18:09:35Z")

</div>

> [@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:

```plaintext
$ 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

```

---

<div class="post-metadata">

**Author:** ![Corona688](https://community.unix.com/letter_avatar/corona688/32/5_5575768a8748004e209b776fc1b2916d.png) [@Corona688](https://community.unix.com/u/Corona688)\
**Post date:** [November 16, 2012, 6:32pm UTC](https://community.unix.com/t/passing-perl-var-values-to-sh-shell-script/319982/4 "2012-11-16T18:32:59Z")

</div>

Should be noted that only works in ksh, other shells will set the variables in a subshell.
