LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   run perl script in linux (https://www.linuxquestions.org/questions/programming-9/run-perl-script-in-linux-824095/)

casualzone 08-04-2010 05:58 AM

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

druuna 08-04-2010 06:01 AM

Hi,

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

Hope this helps.

grail 08-04-2010 06:02 AM

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


casualzone 08-05-2010 12:25 AM

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!

Sergei Steshenko 08-05-2010 12:35 AM

Quote:

Originally Posted by casualzone (Post 4056328)
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.

druuna 08-05-2010 03:16 AM

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.

grail 08-05-2010 04:59 AM

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.

MTK358 08-05-2010 07:05 AM

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


All times are GMT -5. The time now is 09:44 AM.