Re: Perl on a Mac - again

Discussion in 'Perl Misc' started by Peter Makholm, Apr 22, 2012.

  1. Hacker <> writes:

    > When I write 'perl test' on the command line it works fine and comes out with
    > 'Hello World' just as it should, but when I write 'test' on the command line
    > there is no output.


    You current working directory is not in $PATH and you end up with
    calling /bin/test.

    //Makholm
    Peter Makholm, Apr 22, 2012
    #1
    1. Advertising

  2. Peter Makholm

    Tim McDaniel Guest

    In article <>,
    Peter Makholm <> wrote:
    >Hacker <> writes:
    >
    >> When I write 'perl test' on the command line it works fine and
    >> comes out with 'Hello World' just as it should, but when I write
    >> 'test' on the command line there is no output.

    >
    >You current working directory is not in $PATH and you end up with
    >calling /bin/test.


    "test" is a builtin command in bash and probably in other shells.
    It doesn't matter what PATH is set to: it always checks for builtins
    before checking anything in PATH.

    In bash, you can run
    type test
    and it will tell you what it will run for that command.
    In this case, the output is
    test is a shell builtin

    You could run your program as "./test", if it has the execute bit set,
    but if you ever forgot, it would silently run the shell builtin
    again. Bastically, naming a test program "test' is a classic UNIX
    error.

    If you want to run it as a command, then
    - rename the file. Do not rename it to one of the reserved builtin
    commands or such. No builtin has "." in the middle fo text, so
    that's always safe, like "test.pl".

    Suppose below you rename it test1

    - make sure it has the execute bit set, via
    chmod u+x test1
    - run it via
    ./test1
    You may already have "." as an item in $PATH, in which case you can
    run it as "test1", but if you are explicit about the path to the
    file, like "./test1", then there's no question about confusing it
    with a builtin.


    Builtin commands and such:
    Tim McDaniel, Apr 22, 2012
    #2
    1. Advertising

  3. Hacker <> wrote:
    >> You current working directory is not in $PATH and you end up with
    >> calling /bin/test.

    >
    >Would a ~/.bashrc something with path help.


    Don't! There is a very good reason why the CWD is not included in your
    search path. And least of all at the beginning.

    This has been a very frequent Unix beginners complain for the past 2
    decades and I suggest you consult the archives or Unix FAQs for an
    explanation why it is the way it is. Once you understand the reason
    behind it then you can make your own decision if you want to change the
    behaviour for yourself.

    And no, it doesn't have anything to do with Perl.

    >I can not remember how you append $PATH, yuk.


    You should first understand why the CWD is not included in the path.
    Only then can you make a concious and educated decision if for you it
    makes sense to add the CWD or not.

    jue
    Jürgen Exner, Apr 22, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. amit
    Replies:
    0
    Views:
    372
  2. che
    Replies:
    2
    Views:
    475
  3. Dr.Ruud

    Re: Perl on a Mac - again

    Dr.Ruud, Apr 22, 2012, in forum: Perl Misc
    Replies:
    1
    Views:
    543
    Dr.Ruud
    Apr 22, 2012
  4. Martijn Lievaart

    Re: Perl on a Mac - again

    Martijn Lievaart, Apr 22, 2012, in forum: Perl Misc
    Replies:
    6
    Views:
    733
    Peter J. Holzer
    Apr 25, 2012
  5. Jürgen Exner

    Re: Perl on a Mac - again

    Jürgen Exner, Apr 22, 2012, in forum: Perl Misc
    Replies:
    0
    Views:
    566
    Jürgen Exner
    Apr 22, 2012
Loading...

Share This Page