- Turning Perl Scripts into Commands
- The UNIX/Linux Magic String
- Using the env Program
- The Shell Script Method
- Microsoft Windows .bat File
- Resources
The UNIX/Linux Magic String
One way of changing a Perl script into a UNIX or Linux command is to make the first line of the script a "magic string" that tells the operating system that this is a Perl script.
For example, if your perl executable is located in /usr/local/bin, then you can turn your script into a program by putting the line:
#!/usr/local/bin/perl
at the top of your program. (It must be the very first line and must not be preceded by any comments.)
You then need to tell the system that this is an executable program by setting the execute bit for the owner, the owner's group, and all other people:
$ chmod a+x script.pl
Now you can execute the script directly:
$ script.pl
(You may want to rename your file from script.pl to script to be consistent with the standard UNIX naming convention as well.)
$ mv script.pl script
Note that if your Perl interpreter requires any flags such as -I (specify module directory) or -T (turn on security checks), they can be included on the top line as well:
#!/usr/local/bin/perl -T -I/home/oualline/local/lib
The advantages to doing things this way include:
Simple
Works for setuid scripts
The disadvantages are the following:
Non-portable
It is non-portable because the exact path to the perl command must be specified, and this can vary from system to system.