On Thursday, July 11, 2002, at 12:08 , Carson Wilcox wrote:

> I have a need to source a ksh script from within a perl script.
> Does anyone know if this is possible and how to do it.

You may need to help us out here - since this sounds like
you have a set of variables being assigned in a ksh fashion
in a 'file' that would normally be simply 'sourced' into
a ksh script with something like

        . /path/to/file

I have an illustration of this behavior at the end.

In that illustration, in the main, it is about setting
environmental variables - all of which would be accessed
in perl in th %ENV...

the quick solution then is to have a simple wrapper script
that sources all of the env context, and then launches
the perl script.

If on the other hand, one's ksh script is more towards a
'library' where it has a bunch of defined 'functions' -
then your problem can be a bit more complex - and you
have a few strategies to look at:

        a) porting this library to a perl lib,
                with a nice little parser code that knows
                how to translate ksh syntax into perl syntax

        b) build a ksh wrapper that does the sourcing, and
                based upon command line options invokes the
                functions in the ksh lib - so that you can
                call this in any of the standard perl ways
                of back-tick, system() or open(CALL, "wrapper $arg |") ....

so it rather depends upon which you are really trying to solve
with which 'sourcing' you are using.

esoterica note:

I agree with peter on the 'problem' of setting up
the ENV stuff in a child - the solution I have always
used is to 'contain' the ENV information in a script
and then

        exec script

so as to replace the login shell I was originally
working in, with an alternative definition - as
I did with the ksh scriptology below.


ciao
drieux

---

an illustration of a ksh sourcing play

### #!/bin/ksh
###
### CommonDefFile=${HOME}/etc/drieuxTool.dfn
###
### if [ -f ${CommonDefFile} ]
### then
###         . ${CommonDefFile}
### else
###         echo "unable to find  ${CommonDefFile}"
###         exit
### fi
###
### PS="HappyMars > "
### export PS
### ENV=${HOME}/.mars.kshrc
### export ENV
###
### ksh
###
### exit

where it specifically grabs:
vladimir: 60:] sed 's/^/### /' ${HOME}/.mars.kshrc
### #!/bin/ksh
###
### #
### # the common kornsheel things for a Mars Complex
### #
###
### set -o vi
### alias gobin="cd ${MARS_BIN}"
### alias goconf="cd ${MARS_ETC}"
### alias golog="cd ${MARS_VAR}"
### alias golib="cd ${MARS_LIB}"
###
### alias gotools="cd ${MARS_TOOLS_BIN}"
###
### PS1="HappyMarsLand > "
###
###
vladimir: 61:]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to