Why do Perl 5 backtick (` `) calls fail on Linux only?

Posted on 2005-04-25
Last Modified: 2006-11-18
Well, I don't really know what to make of this.  I have run this script on 3 different RedHat boxes, all with the same result.  The same script obviously runs fine on any other Unixy type interp(AIX, HP, Solaris, Windows BASH), but SHOULD run on Linux bash or any other shell for that matter...even if you get a failure.


$binpath = `type perl`;  #don't really care if we get the parsed path here...just want SOMETHING
print "binpath = $binpath\n";


I just don't get it.   This SHOULD work and is very simple.    It works from the CLI, and I am using ActiveState 5.8.6.  It does the same thing on 5.6.  Please don't spend any unnecessary time on this, but if you have any ideas off the top of your head...

I am using RedHat 3.0 AS.

Question by:jchristena
    LVL 20

    Accepted Solution

    The 'type' command is a builtin in only some shells. Unless you have a separate command named 'type' in your PATH, perl is going to look at that string and, seeing no shell metacharacters, try to exec a command named 'type', and silently fail.
    LVL 84

    Expert Comment

    Did you want `which perl` ?
    LVL 48

    Expert Comment

    Your script could not have worked on AIX, HP, Solaris, unless you had a script or binary called 'type', and that isn't a standard command on any of those Unix flavours.

    jmcg has given you the reason why it doesn't work.

    What are you actually trying to acheive?

    Author Comment

    It did work on the other platforms, and I think I have a reason for it.  The default path on my Linux boxes consists of essentially /usr/sbin and thats it.  The other boxes contain /usr/bin and /bin by default which contain the bash and sh binaries.  If I explicitly specify a shell:

    $var = `bash -c \"type perl\"`;

    everything works fine.    In the end, it comes down to the fact that jmcg is correct.  Thanks for all the responses.

    LVL 20

    Expert Comment

    That seems like an odd default path to have. Lots of stuff is not going to work if you can only call on commands present in /usr/sbin.

    My favorite method for finding perl is the one I use on shebang lines:

    #! /usr/bin/env perl

    I needed to go to this when I worked in an environment where I wanted to share my scripts but different machines had been set up with different conventions on finding Perl: some in /usr/bin/perl, some in /usr/local/bin/perl, and, on one machine, /var/local/bin/perl.

    You haven't explained quite what you're trying to do, but rather than call an external command, it might be simpler to do:

       for (map {"$_/perl"} split /:/, $ENV{PATH}) { if( -x $_) {$binpath=$_; last}}


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    binary to char / hexadecimal 5 93
    Perl - Mawk 2 57
    transpose into pipe delemited 8 61
    Perl script not writing to .csv file 6 88
    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    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…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    729 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

    20 Experts available now in Live!

    Get 1:1 Help Now