On Fri, 17 Oct 2003 14:32:07 -0400
Steve Grazzini <[EMAIL PROTECTED]> wrote:

> 
> Have you actually tried ". perlscript" ?  :-)
> 

This will not work.  The shell "." command for the Bourne and Korn shell
effectively sources the file and expects it to contain shell commands.

You can fork a shell from a perl script using either the "system" perl
function (if you do not want to capture the output in the shell script)
or with the backtic notation if you do.

Creating an alias and then executing the alias later is a bit trickier,
since the context of the alias is not saved between the system or
backtic calls. They are seperate invocations of the shell. You need to
redefine the alias within each system or backtic call.

I have done stuff with both the system and backtic calls which sets the
execution environment in the subshell and then does something else. 
Since system or backtic invokes the shell as "sh -c command...", you can
do something in Perl like:

system("ENVVAR=whatever; export ENVVAR; command");

Note that the shell called is /bin/sh (on Unix anyway). So the syntax of
the command passed to system is Bourne shell specific, if you want the
call to be portable across different Unix systems.  Not sure what
happens in Windows.

If you want to use a specific shell then you have to be explicit
about the calling sequence. e.g.

system("ksh -c \"export TEST=hello; echo \\\$TEST\"");

Note the quoting gets really convoluted, since you have to worry about
Perl's quoting conventions and two layers of shell quoting. Anything
more complicated than this short example and I would go ahead and create
a shell script and call it explicitly.

Better, yet, write the shell functionality in Perl and do away with
the subshell calls altogether. ;-)

--
Smoot Carl-Mitchell
Systems/Networking Consultant
email: [EMAIL PROTECTED]
cell: +1 602 421 9005
home: +1 480 922 7313

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

Reply via email to