Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6112943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:48:09+00:00 2026-05-23T14:48:09+00:00

I have a very short tutorial perl script: #!/usr/bin/perl print The date is ,`date`;

  • 0

I have a very short tutorial perl script:

#!/usr/bin/perl
print "The date is ",`date`;
print "The date is `date`",".\n";
$directory=`pwd`;
print "\nThe current directory is $directory.";

and the output:

The date is Sat Jul  2 17:04:58 PDT 2011
The date is `date`.

The current directory is total 20
-rwxr-xr-x 1 yan yan 433 2011-07-02 15:58 36
-rwxr-xr-x 1 yan yan 313 2011-07-02 16:29 43
-rwxr-xr-x 1 yan yan 116 2011-07-02 16:51 45
-rwxr-xr-x 1 yan yan 149 2011-07-02 16:53 46
-rwxr-xr-x 1 yan yan 145 2011-07-02 17:02 47

But if I just run pwd I got:

yan@ubuntu:~/bin/blackperl$ pwd
/home/yan/bin/blackperl

Any logical explanation to the mystery here? thanks a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:48:09+00:00Added an answer on May 23, 2026 at 2:48 pm

    A possible explanation for the mystery:

    You have some program named pwd in the command search path (i.e. in one of the directories named by the PATH environment variable) which does these strange things. When executing pwd in your interactive shell (bash) or in a shell script (dash), you get the buildin command pwd, which prints the current working directory, as it should.

    On the other hand, in your Perl source line

    $directory=`pwd`;
    

    Perl does not invoke the system’s shell by using the C system() function, but instead directly executes the pwd command in the path (using the execvp() call in a forked process), since the command looks simple enough (a simple command, in bash terminology). If this pwd binary is not the usual /bin/pwd binary (which also simply prints the current directory), but instead does something like ls -l, we get the observed behaviour.

    The real solution would be to fix your PATH and/or remove the bogus pwd binary. Use which pwd to find out where it is (or type -a pwd on bash).

    A solution from the Perl side would be to force a shell call:

    $directory=`pwd;`;
    

    This forces Perl to call the shell instead of directly executing the program. (More generally, any shell metacharacter has this effect. This is described only for Perl’s system function, not for the quote-execute operator.)

    In this case Perl would invoke /bin/sh, which in Ubuntu (at least in current versions, I’m not sure about your 9.10) is dash (Debian Almquist Shell) instead of bash (GNU’s Bourne Again Shell). Dash is a much simpler (and faster) sh implementation than bash, but for things like pwd there should be no difference (it is a buildin in my dash, too), as long as you have no aliases or shell functions defined in one shell and not the other.

    Of course, a better solution would be to use Perl’s Cwd module, as recommended in the answer by toolic.


    Thanks to ikegami for explaining the semantics of the backticks operator to me in the comments to the question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a console application which has target .NET 2.0 It is very short
I'm following the List View tutorial and I have this code (very minor modifications):
Two questions in one, but I have a very short test case demonstrating my
In a very short and simple LVL callback function, I have: public void applicationError(ApplicationErrorCode
I have a number of very long arrays. No run-time sort is possible. It
I have an XML file that is very long, but here is a shot
I am very confused. I have this lambda expression: tvPatientPrecriptionsEntities.Sort((p1, p2) => p1.MedicationStartDate .Value
We have very strange problem, one of our applications is continually querying server by
I have very little experience building software for Windows, and zero experience using the
i have very simple problem. I need to create model, that represent element of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.