Get the File name of perl executable in Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the File name of perl executable in Linux
# 1  
Old 04-19-2013
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
# 2  
Old 04-20-2013
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:
Code:
#!/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:
Code:
% ./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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to make a .exe file executable in Linux?

Dear all, I download a .exe file in my current folder called: ukbmd5.exe. I was told to run the command below: ukbmd5 ukb25278.enc to verify the integrity of the files that you have downloaded and the program ukbmd5 has been made available to assist with decrpying ukb25278.enc. while when I run... (1 Reply)
Discussion started by: forevertl
1 Replies

2. Shell Programming and Scripting

Shell script to encrypt the xls file using executable jar in Linux SUSE 11.4

Dear Experts, I am an ERP consultant and would like to learn shell script. We are working on Linux SUSE 11.4 and I am very new to shell scripting. We can manually encrypt an excel file using "executable jar" through command prompt by placing the jar file & the file to be encrypted on a physical... (1 Reply)
Discussion started by: nithin226
1 Replies

3. UNIX for Dummies Questions & Answers

What are the executable file formats in Solaris and Linux?

we all knew that .exe files are the executable file formats in windows....... Similarly, what are the executable file formats in solaris and linux ........ please tell me:D Thanks in Advance. (2 Replies)
Discussion started by: vamshigvk475
2 Replies

4. Shell Programming and Scripting

Making a perl script executable

Hello, I have a perl program called snp_hwe.pl I have another program called hwe_test.run which contains the following: for file in *.inp do cp $file genotype_counts_c.txt ./snp_hwe.exe > $file'.res' done I want to change my perl program to an executable program while changing... (3 Replies)
Discussion started by: Homa
3 Replies

5. UNIX for Dummies Questions & Answers

[Solved] About commands for linux executable files

I have seen commands like this: (hello is the executable file or maybe script file) ./hello hello .hello So, anyone could tell me the differences among these commands? (2 Replies)
Discussion started by: icyfight
2 Replies

6. Shell Programming and Scripting

perl script to open an executable and pass the user credentials

Is it possible to open an executable file and pass user credentials through the perl script. If yes Please do share the CPAN module names and the way to access the executable file. For eg. I want to open the IBM LOTUS Sametime through my perl code and pass the user credentials like... (1 Reply)
Discussion started by: giridhar276
1 Replies

7. Linux

Size of the Library/Executable is high in LINUX

HI All, We have a 32bit Gui application created using C++. We ported the application from Solaris to Linux. Issue we are facing is the size of the library and executable is very large in LINUX compared to Solaris. Red Hat Enterprise Linux 5.4 is the Linux version we using. Please... (0 Replies)
Discussion started by: sanushchacko
0 Replies

8. Shell Programming and Scripting

Perl : find perl executable binary

Hi I have an oracle perl script running as cron job across multiple unix servers. The issue is the perl binary is found in multiple directories I use in the start of the script ... #!/usr/bin/perl on some servers the script fails because /usr/bin/perl is not present. Is there a way i can... (4 Replies)
Discussion started by: PrasannaKS
4 Replies

9. UNIX for Dummies Questions & Answers

Linux PHP Executable Output Issue with IE

I have developed a PHP web page that executes a batch file and pipes the output to a file. It works fine when using Firefox, Safari, etc. However, when using IE, it does not work. $execute = `batch.bat $var1 $var2 | tee /batch.output`; print "<pre>$execute</pre>"; When the page is run in... (1 Reply)
Discussion started by: dleblanc67
1 Replies

10. Shell Programming and Scripting

calling a C executable from inside a Perl script

here's the Perl code snippet... how can i call my C executable 'porter-stemmer' and pass it $1 as an argument? Thanks for the help! # Read through the original topic set, and modify based on the current # pre-processing options while (<TOPIC_ORIG>) { # Run pre-processing over only the... (3 Replies)
Discussion started by: mark_nsx
3 Replies
Login or Register to Ask a Question