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,” which tells the operating system that this is a Perl script.

For example, if your perl executable is located in /usr/local/bin, you turn your script into a program by putting the line

#!/usr/local/bin/perl
at the top of your program. (It must be the 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, owner’s group, and all other people:

$ chmod a+x script.pl

Now you can execute the script ...

Get Perl for C Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.