Messed up Perl

Ryan Schmidt ryandesign at
Sun Oct 3 17:41:45 PDT 2010

On Oct 3, 2010, at 18:41, Hal Vaughan wrote:

> On Oct 3, 2010, at 7:25 PM, Jon Hermansen wrote:
>>> I just found out that on my iMac, the "perl" command is now /opt/local/bin/perl and not /usr/bin/perl.  Now maybe that's not a big issue, since I have a kerbang at the start of all my scripts, but there's more of a problem.
>> You probably want to modify your PATH environment variable, or start overriding your shebang line by not running it like this:
> On the iMac itself, when not doing anything in MacPorts, do you know if there's a priority set when specifying PATH in something like .bash_profile?  In other words, if I have "/usr/bin/" before "/opt/local/bin", does it search /usr/bin for an executable before searching /opt/local/bin?

Yes, that is correct. Paths are tried in the order specified.

>> ./
> So if I have a shebang "#!/usr/bin/perl" and still run a program from the command line without specifying, it will use the perl executable specified, won't it?

Yes, that's correct. If you have a shebang line "#!/usr/bin/perl" in, and's executable bit is set, an you run "./", will be processed by /usr/bin/perl. And you can override the shebang line by running with whatever perl you choose, e.g. "/opt/local/bin/perl" will use /opt/local/bin/perl to process it.

> Part of it is that I also have a MacMini that's a server on my LAN.  While this script is a special case, in general, I'd rather keep a program as global as possible.  This script could easily be modified to be quite useful at other times in the future, as well and I could see using it on either Mac, or even on a Linux or Windows box in the future, so if I can just stick with "#!/usr/bin/perl" I'd prefer it.  (I know -- Windows is a whole 'nother story!"

The most general thing to do would be to specify the shebang line as "#!/usr/bin/env perl", that way perl gets found wherever in the environment the user has specified it to be (e.g. using the PATH variable).

> The only issue with that is I wanted to do it permanently and I'm still looking for info on how to control Mac environment variables -- other than setting in .bash_profile, and I like to know if something else will be effected when I make a change.

Setting PATH in .bash_profile (or .profile) is the correct way to do it.

Most users want and expect MacPorts software to be available in the terminal simply by typing the relevant command name (i.e. without having to type the full path to that command), which is why MacPorts inserts a line in your .bash_profile (or .profile) to modify the PATH. If you don't want that behavior you can remove MacPorts' modification to your .bash_profile (or .profile).

More information about the macports-users mailing list