public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* sourcing a perl script on cygwin
       [not found] ` <435f371f0806270055p7555331dt18cd8c868c7e208@mail.gmail.com>
@ 2008-06-27  8:09   ` Florin Barbalau
  2008-06-27 12:04     ` Brian Dessent
  0 siblings, 1 reply; 6+ messages in thread
From: Florin Barbalau @ 2008-06-27  8:09 UTC (permalink / raw)
  To: cygwin

Hello,

 I have a windows server 2003 installation and I try to sun a script
for an Oracle patch installation. I installed cygwin. The files in
question are two and they have more or less the following content:

install_cdaa.sh
------------------------
#!/bin/sh

# Check if ORACLE_HOME has been set
if [ -z "$ORACLE_HOME" ]
then
  echo "Set the ORACLE_HOME environment variable"
        exit 1
 fi
# Set the IFS_HOME variable
export IFS_HOME=${ORACLE_HOME}/content

##
## Setting other environment variables
#
. ${IFS_HOME}/bin/system/ifssetenv.pl

....
....
....

# EOF

 ///////////////

then we have :

ifssetenv.pl
------------------

#!/bin/perl

# ifssetenv.pl
#
# Oracle Internet File System
# Copyright (c) 2002, 2005, Oracle. All rights reserved.
 #

#
# This script sets the environment to run iFS.  The only environment
variable
# you must manually set is ORACLE_HOME.  The environment variables
IFS_JAVA_HOME
# and IFS_JAVA_COMMAND may be optionally set; otherwise default values
 will be
# used.
#
# The environment variable IFS_INSTALL_ENVIRONMENT is reserved for
Oracle use.
# Do not set this environment variable in your install environment.
#
# Oracle recommends that you not change this script.
 #
#
#   Set variables
#

#   The Oracle instance in which iFS was installed;
#   Set by the iFS Configuration Assistant
#

use Cwd;
use File::Basename;

if (lc($^O) eq "mswin32")
 {
  $PSEP = ";";
}

....
....
....
#EOF

////////////////////////////////
//////////////////////////////
I take the following steps in a new cygwin windows:

export ORACLE_HOME=/cygdrive/d/cdb_10_2

then If i run:
$ /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl
it works ok.

but if I try to source as in the calling script (install_cdaa.sh) I
get error messages. :
$ . /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl
 bash: use: command not found
bash: use: command not found
bash: /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl: line 31:
syntax erro
r near unexpected token `$^O'
bash: /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl: line 31:
 `if (lc($^O
) eq "mswin32")'

do you have any ideea why?

thanks,
Florin

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sourcing a perl script on cygwin
  2008-06-27  8:09   ` sourcing a perl script on cygwin Florin Barbalau
@ 2008-06-27 12:04     ` Brian Dessent
  2008-06-27 13:25       ` Florin Barbalau
  0 siblings, 1 reply; 6+ messages in thread
From: Brian Dessent @ 2008-06-27 12:04 UTC (permalink / raw)
  To: cygwin

Florin Barbalau wrote:

> then If i run:
> $ /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl
> it works ok.
> 
> but if I try to source as in the calling script (install_cdaa.sh) I
> get error messages. :
> $ . /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl
>  bash: use: command not found
> bash: use: command not found
> bash: /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl: line 31:
> syntax erro
> r near unexpected token `$^O'
> bash: /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl: line 31:
>  `if (lc($^O
> ) eq "mswin32")'
> 
> do you have any ideea why?

You have a misunderstanding of what sourcing means.  When you tell the
shell to source a file it expects to read shell commands from that
file.  It doesn't expect to find foreign commands in another language
like perl, and it doesn't honor the shebang since that is just a comment
in shell syntax.  When you run a script, as opposed to sourcing it, the
OS (in this case Cygwin) reads the shebang line (#!/bin/perl) to know
what program to use to interpret the script, which is why that works.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sourcing a perl script on cygwin
  2008-06-27 12:04     ` Brian Dessent
@ 2008-06-27 13:25       ` Florin Barbalau
  2008-06-27 13:36         ` Brian Dessent
  0 siblings, 1 reply; 6+ messages in thread
From: Florin Barbalau @ 2008-06-27 13:25 UTC (permalink / raw)
  To: cygwin

Hello Brian,

thanks for the explication. so I should understand that I can never
run a perl script like this in order to set environment variables for
the calling one ?

I am very surprised about this problem because this is in the
installation of an Oracle patch.

many thanks,
Florin

On 6/27/08, Brian Dessent <brian@dessent.net> wrote:
> Florin Barbalau wrote:
>
>  > then If i run:
>  > $ /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl
>  > it works ok.
>  >
>  > but if I try to source as in the calling script (install_cdaa.sh) I
>  > get error messages. :
>  > $ . /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl
>  >  bash: use: command not found
>  > bash: use: command not found
>  > bash: /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl: line 31:
>  > syntax erro
>  > r near unexpected token `$^O'
>  > bash: /cygdrive/d/cdb_10_2/content/bin/system/ifssetenv.pl: line 31:
>  >  `if (lc($^O
>  > ) eq "mswin32")'
>  >
>  > do you have any ideea why?
>
>
> You have a misunderstanding of what sourcing means.  When you tell the
>  shell to source a file it expects to read shell commands from that
>  file.  It doesn't expect to find foreign commands in another language
>  like perl, and it doesn't honor the shebang since that is just a comment
>  in shell syntax.  When you run a script, as opposed to sourcing it, the
>  OS (in this case Cygwin) reads the shebang line (#!/bin/perl) to know
>  what program to use to interpret the script, which is why that works.
>
>  Brian
>
>
>  --
>  Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>  Problem reports:       http://cygwin.com/problems.html
>  Documentation:         http://cygwin.com/docs.html
>  FAQ:                   http://cygwin.com/faq/
>
>

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sourcing a perl script on cygwin
  2008-06-27 13:25       ` Florin Barbalau
@ 2008-06-27 13:36         ` Brian Dessent
  2008-06-27 15:01           ` Florin Barbalau
  0 siblings, 1 reply; 6+ messages in thread
From: Brian Dessent @ 2008-06-27 13:36 UTC (permalink / raw)
  To: cygwin

Florin Barbalau wrote:

> thanks for the explication. so I should understand that I can never
> run a perl script like this in order to set environment variables for
> the calling one ?
> 
> I am very surprised about this problem because this is in the
> installation of an Oracle patch.

I don't see how that could ever possibly hope to work.  In order to
execute perl, you have to create a perl process.  Any changes to the
environment that that perl process makes will be completely discarded
when it exits, i.e. it's impossible for a child to modify a parent's
environment.

Are you sure that the perl script wasn't intended to be the parent
process of the shell, i.e. it sets up a modified environment and then
drops you in a (sub)shell with those changes?  If that's the case then
simply execing the perl script should work.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sourcing a perl script on cygwin
  2008-06-27 13:36         ` Brian Dessent
@ 2008-06-27 15:01           ` Florin Barbalau
  2008-06-27 15:31             ` Brian Dessent
  0 siblings, 1 reply; 6+ messages in thread
From: Florin Barbalau @ 2008-06-27 15:01 UTC (permalink / raw)
  To: cygwin

I understand that I can call a shell script from a perl script by
using the command:

 exec("shell_script_name");

but when proceeding this way I don't have the environment variables
that were set in the perl script. Is there anther way to call the
shell script so that the shell child receives them?

Thanks,
Florin

On 6/27/08, Brian Dessent <brian@dessent.net> wrote:
> Florin Barbalau wrote:
>
>  > thanks for the explication. so I should understand that I can never
>  > run a perl script like this in order to set environment variables for
>  > the calling one ?
>  >
>  > I am very surprised about this problem because this is in the
>  > installation of an Oracle patch.
>
>
> I don't see how that could ever possibly hope to work.  In order to
>  execute perl, you have to create a perl process.  Any changes to the
>  environment that that perl process makes will be completely discarded
>  when it exits, i.e. it's impossible for a child to modify a parent's
>  environment.
>
>  Are you sure that the perl script wasn't intended to be the parent
>  process of the shell, i.e. it sets up a modified environment and then
>  drops you in a (sub)shell with those changes?  If that's the case then
>  simply execing the perl script should work.
>
>
>  Brian
>
>  --
>  Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
>  Problem reports:       http://cygwin.com/problems.html
>  Documentation:         http://cygwin.com/docs.html
>  FAQ:                   http://cygwin.com/faq/
>
>

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: sourcing a perl script on cygwin
  2008-06-27 15:01           ` Florin Barbalau
@ 2008-06-27 15:31             ` Brian Dessent
  0 siblings, 0 replies; 6+ messages in thread
From: Brian Dessent @ 2008-06-27 15:31 UTC (permalink / raw)
  To: cygwin

Florin Barbalau wrote:

> I understand that I can call a shell script from a perl script by
> using the command:
> 
>  exec("shell_script_name");
> 
> but when proceeding this way I don't have the environment variables
> that were set in the perl script. Is there anther way to call the
> shell script so that the shell child receives them?

A simple testcase shows that this does work:

$ cat parent.pl
#!/usr/bin/perl -w

$ENV{'SOMEVAR'} = 'this value set in parent.pl';
exec("child.sh");

$ cat child.sh
#!/bin/sh

echo "SOMEVAR = $SOMEVAR"

$ ./child.sh
SOMEVAR = 

$ ./parent.pl
SOMEVAR = this value set in parent.pl

Whatever is happening in your case therefore is not because the
variables are not being inherited, but due to something else -- for
example your ~/.bashrc could contain commands to set variables,
clobbering the inherited values.  If that's the case then either modify
the startup files to not clobber the vars if they're already set, or
inhibit the shell from reading startup files with --norc and/or
--noprofile.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-06-27 14:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <435f371f0806270051g7734f46ai9be6649011a05cbe@mail.gmail.com>
     [not found] ` <435f371f0806270055p7555331dt18cd8c868c7e208@mail.gmail.com>
2008-06-27  8:09   ` sourcing a perl script on cygwin Florin Barbalau
2008-06-27 12:04     ` Brian Dessent
2008-06-27 13:25       ` Florin Barbalau
2008-06-27 13:36         ` Brian Dessent
2008-06-27 15:01           ` Florin Barbalau
2008-06-27 15:31             ` Brian Dessent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).