"Redirecting" a Shebang Line

Posted on 2011-10-02
Last Modified: 2012-05-12
I produce Perl CGI scripts for some websites. Some of these scripts were written some time ago when I was using WindowsXP with ActivePerl version 5.8 installed. When I moved over to a Mac a few years ago I installed the same ActivePerl version on the Mac and continued to use it to develop new scripts, changing PATH to point to that version of Perl - the live server that is running these scripts is still on version 5.8.

Everything works fine when I’m working locally with these scripts. However I use MAMP to set up virtual hosts for the various websites so that I can test the scripts on my server before uploading them to the live one. The shebang line in these scripts is the usual /usr/bin/perl one so when I run the scripts on my server it uses the Mac’s inbuilt version of Perl, which for Lion is 5.12. My problem is that I have a module installed on the ActiveState Perl version 5.8 that I’ve not been able to install on the Mac’s 5.12 using CPAN, possibly because although I’ve changed the PATH variable to remove the path to 5.8 it is somehow still getting confused about which version of Perl it is trying to add the module to. I've installed the Developer Tools for Lion so this is not the problem.

I can get round this by changing the shebang line to point to Perl 5.8 but then I’ve got to remember to change it back again before I upload it to the live server. I was wondering if there is any way, by changing the Apache settings or otherwise, of leaving the original shebang line and arranging for my server to use Perl 5.8 rather than the inbuilt 5.12.
Question by:RobbieSnr
    LVL 50

    Accepted Solution

    Rename the perl executables to perl-5.8 and perl-5.12 respectively.  Create a soft link /usr/bin/perl pointing to the version you want to use.

    Author Comment

    Many thanks for this suggestion.

    I've just got one question. I suppose that in case the renaming of the inbuilt perl-5.12 caused any problems with the Mac OS I could leave it as it is, just renaming the perl-5.8 one? I'll give this a try.

    Author Comment

    I've now got this working, many thanks.

    I'm very much a beginner as far as bash is concerned and I see that I have to get rid of /usr/bin/perl before I can set up the symbolic link. In fact the /usr/bin/ folder already has a perl5.12 entry. I've set up the link and my shebang line is now redirecting to Perl 5.8 all right. A lot easier than I thought this would be - great.

    Author Closing Comment

    A very simple solution to my problem.
    LVL 50

    Expert Comment

    by:Steve Bink
    And if you ever need to put the 5.12 back into service, just change the soft link to point to the other version.  Good luck!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    Syslogd is a utility that traps and logs messages sent by running processes. It is configured with the syslog.conf file, which consists of lines containing a pair of fields: "the selector field which specifies the types of messages and priorities to…
    In this article we have discussed about the OS X EI Capitan and how to fix Wi-Fi issue in OS X El Capitan. We have explained how to delete system level preferences and create a new Wi-Fi location to resolve Wi-Fi issue.
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now