Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 983
  • Last Modified:

How do I run a perl script on Linux without typing 'perl'

I have a perl script which can be run on Linux by typing 'perl  script.pl  arg'. But I want to run it without having to type the word 'perl' like this 'script.pl  args'. There is an already existing file which runs without typing 'perl', so I know that there are no system settings required to be done. Also, I have included #usr/bin/perl and also changed the chmod to 755. None of this seems to work.
0
przach
Asked:
przach
3 Solutions
 
FishMongerCommented:
The first line in the file is called the "shebang line" and holds the full path to perl

A common shebang line would be:
#!/usr/bin/perl

http://en.wikipedia.org/wiki/Shebang_(Unix)

The path may be different on your system.

If you're in the same directory as the script, you need to specify the path to the script, either full or relative path.
[root@fc4dev ~]# ./test.pl
0
 
przachAuthor Commented:
I tried '>which perl' and it returned #!usr/local/bin/perl. I tried changing the shebang line to #!usr/local/bin/perl and it still doesnt work. But I do not understand where and how to specify the path as you have shown. I am in the same directory as my script.
0
 
malklaviousCommented:
Make sure the permissions of the file are set to executable.  When you run the script you may need to start the command with "./"

ie:

./myScript.pl
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Todd MummertCommented:

For you,as FishMonger said, the first line of your perl script should then be

#!/;usr/local/bin/perl

In addtion, you have to make your script executable

chmod a+x script.pl

then you can either type the bare name of the script (if it is on your PATH), or give the full or relative path to your script

script.pl
./script.pl
/home/mydir/script.pl


what error are you getting?


0
 
przachAuthor Commented:
I have changed the mode to executable. When I try giving:
./script.pl <args>

it does not accept args. It says this:
No such file or directory at line 19. And my line 19 is:
open INPUT, $input or die $!;

But if I run the script without ./ it says command not found.
0
 
Todd MummertCommented:

we've solved the executability problem...you need to use ./script.pl

the other problem is simply a perl coding problem

you're probably doing something like this to find the file you want to open


$input = <>;

you probably need to get rid of the newline at the end of the string

so, use:

$input = <>;
chomp($input);
0
 
Kerem ERSOYPresidentCommented:
If you get an error on line 19 it measn that You've been running your script so your problem has ben solved !!! Congratulations. As to why you get an error at line 19 is probably ou're running the program from your current path in most cases it is your home directory that your file is not in there but under another folder.

./  means th program is under your current path and unlike windows current path is not included in your default path. To include the current path to the search path you can type this command:

export PATH=$PATH:.

Then it will run the script from current directory without ./ . If you want to mate this beaviour defualt then modefy the PATH statement in your .bashrc.

Cheers,
K.
0
 
przachAuthor Commented:
Great!!! That worked. Thank you all.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now