Get the File name of perl executable in Linux

Hi All,

I just want to know how to get the executable name of the perl script as i know "$0" will give me the script name but i want to know the executable name which i got it from the script using pp command.

Regards
Raj

Hi.

One solution is to have the original file name set as a variable in the source. One way to do that is to use version control. Here's an example that uses the checkin function of rcs:

#!/usr/bin/env bash

# @(#) s1	Demonstrate retaining original perl source file with pp.

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C perl rcs ci pp

rm -rf RCS p1,v
FILE=p1
cp sacred p1

pl " Input data file $FILE:"
head $FILE

pl " Results, execute perl file without compile:"
./p1

pl " Save file with version control, display new version:"
ci -l -t-"" $FILE
head $FILE

pl " Execute version controlled perl file without compile:"
./p1

pl " Results, save version, compile and execute a.out from pp:"
rm -f a.out
pp $FILE
./a.out
pe
file a.out

pl " Modify, save, run source again:"
sed -i "s/world/people/" $FILE
ci -l $FILE <<<" "
./p1

exit 0

prodiucing:

% ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
bash GNU bash 3.2.39
perl 5.10.0
RCS version 5.7
ci RCS version 5.7
pp PAR Packager, version 0.978 (PAR version 0.980)

-----
 Input data file p1:
#!/usr/bin/env perl

# @(#) p1	Demonstrate retain source name with version control (rcs, etc.).

$t1 = '$RCSfile$';
$t1 =~ / (\w+),v /;
$program = $1;
print " Hello, world from $0 or $program.\n";

-----
 Results, execute perl file without compile:
 Hello, world from ./p1 or .

-----
 Save file with version control, display new version:
p1,v  <--  p1
initial revision: 1.1
done
#!/usr/bin/env perl

# @(#) p1	Demonstrate retain source name with version control (rcs, etc.).

$t1 = '$RCSfile: p1,v $';
$t1 =~ / (\w+),v /;
$program = $1;
print " Hello, world from $0 or $program.\n";

-----
 Execute version controlled perl file without compile:
 Hello, world from ./p1 or p1.

-----
 Results, save version, compile and execute a.out from pp:
 Hello, world from ./a.out or p1.

a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.8, stripped

-----
 Modify, save, run source again:
p1,v  <--  p1
new revision: 1.2; previous revision: 1.1
done
 Hello, people from ./p1 or p1.

Several utilities can do this, cvs, subversion, etc. Although git is becoming poepular, I have not tried it.

See man pages for details.

Best wishes ... cheers, drl