perlfellas has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have one shell script which calls a perl script.
Is there any way to identify the calling shell script name within the perl script?

Thanks for your help.

20050515 Edit by ysth: change pre tags to p,br

Replies are listed 'Best First'.
Re: How to get the shell script name
by Transient (Hermit) on May 13, 2005 at 15:15 UTC
    You could pass it in as an argument.

    $0 is the program name, so call the perl script with that argument.

    e.g.
    # shell script: perl myscript.pl $0 ---- #perl script: print "Called by: ", $ARGV[0], "\n";
Re: How to get the shell script name
by Roy Johnson (Monsignor) on May 13, 2005 at 15:30 UTC
    You could getppid and then search the process list, but it would be a lot easier if you passed it to the script, or exported it in the shell script so that the perl script could find it in %ENV.

    Caution: Contents may have been coded under pressure.