LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-04-2010, 05:58 AM   #1
casualzone
Member
 
Registered: Jan 2010
Posts: 189

Rep: Reputation: 15
run perl script in linux


Here is the perl script test case called hello.pl

#!/usr/bin/perl
print "Hello world!\n";


the command to invoke the script in the terminal as:
#perl hello.pl

How could I execute it without the "perl" prefix as:
#hello.pl

I have chmod 777 hello.pl

#which perl
/usr/bin/perl
 
Old 08-04-2010, 06:01 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

If the location the script is in is not in your PATH: ./hello.pl

Hope this helps.
 
Old 08-04-2010, 06:02 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,442

Rep: Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880
You may run any executable file by providing the full (absolute) or relative path.
So assuming you are in your home directory, any of the following can work:
Code:
/home/casualzone/hello.pl

~/hello.pl

./hello.pl
 
Old 08-05-2010, 12:25 AM   #4
casualzone
Member
 
Registered: Jan 2010
Posts: 189

Original Poster
Rep: Reputation: 15
thank you very much!! It works by executing below:
#/app/work/hello.pl

The next step / question.

If the perl script is located at /app/work/, how could I make it as below

in the /app/work/ folder
#hello.pl

instead of typing
#/app/work/hello.pl

Reason: I am using the script frequently.

That mean i got to export the /app/work/ path into my .bashrc ?? How could I make it?
thank you!

Last edited by casualzone; 08-05-2010 at 12:27 AM.
 
Old 08-05-2010, 12:35 AM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by casualzone View Post
thank you very much!! It works by executing below:
#/app/work/hello.pl

The next step / question.

If the perl script is located at /app/work/, how could I make it as below

in the /app/work/ folder
#hello.pl

instead of typing
#/app/work/hello.pl

Reason: I am using the script frequently.

That mean i got to export the /app/work/ path into my .bashrc ?? How could I make it?
thank you!
Read about PATH environment variable (use WEB search engine of your liking). The concept of PATH, by the way, is not UNIX/Linux specific - Windows uses the concept too.

And/or read about "bash aliases" - again, use WEB search engine of your liking.

Last edited by Sergei Steshenko; 08-05-2010 at 12:36 AM.
 
Old 08-05-2010, 03:16 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Hi,

If you want to add something to your PATH you can edit your /etc/profile (make it global for every user) or your ~/.bashrc (or ~/.bash_profile). The latter depends a bit on your distro.

As stated already by Sergei Steshenko, search the web for specifics (do include your distro name in the search).

Hope this helps.
 
Old 08-05-2010, 04:59 AM   #7
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,442

Rep: Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880Reputation: 1880
If only required on a temporary basis, ie you might move directories later, then you can use the third option from post #3 when in the directory.
 
Old 08-05-2010, 07:05 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
I have a directory called "bin" in my home dir and I added it to my (and only my) PATH using .bash_profile.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to run script on the server from client machine in windows in a perl script vpradeep Linux - Newbie 2 09-01-2008 03:29 AM
MySQL Updates With Null When Perl Script Run From Shell Script ThisGuyIKnow Programming 6 08-12-2008 09:56 AM
how do I run a perl script in linux izquierdista Linux - Software 6 07-07-2007 10:54 PM
how to run a shell script in the perl script sharad Linux - General 1 05-24-2006 03:23 AM
How to run a perl script as a daemon ? paonethestar Programming 17 11-06-2003 08:53 PM


All times are GMT -5. The time now is 08:49 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration