Choosing the path based on the system "uname" command

Discussion in 'Perl Misc' started by doni, Feb 27, 2007.

  1. doni

    doni Guest

    Hi,

    I want to write a program that does check the appropriate system path
    for perl in FreeBSD and Linux.

    The path where I have it in FreeBSD is
    #! /usr/local/bin/perl

    and the path where it is in Linux is
    #! /usr/bin/perl

    I wanted the program to check for the uname of the system and choose
    the appropriate path. Can anyone tell me how can I have my program
    check this.

    This is how I wrote the program but it doesnt work.

    #! /usr/local/bin/perl

    use strict;
    use warnings;

    if (system("uname") eq "Linux") {
    #! /usr/bin/perl
    }

    < rest of the code >

    Thanks,
    doni
    doni, Feb 27, 2007
    #1
    1. Advertising

  2. doni

    Paul Lalli Guest

    On Feb 27, 2:49 pm, "doni" <> wrote:
    > Hi,
    >
    > I want to write a program that does check the appropriate system path
    > for perl in FreeBSD and Linux.
    >
    > The path where I have it in FreeBSD is
    > #! /usr/local/bin/perl
    >
    > and the path where it is in Linux is
    > #! /usr/bin/perl
    >
    > I wanted the program to check for the uname of the system and choose
    > the appropriate path. Can anyone tell me how can I have my program
    > check this.
    >
    > This is how I wrote the program but it doesnt work.
    >
    > #! /usr/local/bin/perl
    >
    > use strict;
    > use warnings;
    >
    > if (system("uname") eq "Linux") {


    What do you think that does?

    Please read the documentation for the function you're using

    perldoc -f system
    perldoc -q system


    > #! /usr/bin/perl


    That's a comment, and nothing more. The #! syntax means nothing
    unless it's the first two characters of the file.

    You probably meant to do an exec()

    perldoc -f exec

    And to avoid an infinite loop, you'll need to make sure you're not
    already executing the version you meant to. I think you'll need both
    the $0 and $^X variables. You can read about them in:
    perldoc perlvar
    In fact, you could probably get rid of the call to uname entirely, by
    using the $^0 variable, also documented in that perldoc.

    Hope that helps,
    Paul Lalli
    Paul Lalli, Feb 27, 2007
    #2
    1. Advertising

  3. doni

    J. Gleixner Guest

    doni wrote:
    > Hi,
    >
    > I want to write a program that does check the appropriate system path
    > for perl in FreeBSD and Linux.
    >
    > The path where I have it in FreeBSD is
    > #! /usr/local/bin/perl
    >
    > and the path where it is in Linux is
    > #! /usr/bin/perl
    >
    > I wanted the program to check for the uname of the system and choose
    > the appropriate path. Can anyone tell me how can I have my program
    > check this.



    Easier to use a symlink or on your Freebsd box (it's probably on your
    Linux box also), run 'use.perl port', then /usr/bin/perl will work
    on both.
    J. Gleixner, Feb 27, 2007
    #3
  4. doni

    Ben Morrow Guest

    Quoth "doni" <>:
    > Hi,
    >
    > I want to write a program that does check the appropriate system path
    > for perl in FreeBSD and Linux.
    >
    > The path where I have it in FreeBSD is
    > #! /usr/local/bin/perl
    >
    > and the path where it is in Linux is
    > #! /usr/bin/perl
    >
    > I wanted the program to check for the uname of the system and choose
    > the appropriate path. Can anyone tell me how can I have my program
    > check this.


    This is not a Perl question. The path on the #! line is not used by
    perl, but by your operating system. In general, there is no way to put
    any logic into that line, though

    #!/usr/bin/env perl

    may do what you want. Note that it will use the perl in your current
    PATH, which may be a security risk. As others have said, you are much
    better off arranging for perl to be available as /usr/bin/perl, or
    writing some sort of installation script that changes the #! line.

    Ben

    --
    For far more marvellous is the truth than any artists of the past imagined!
    Why do the poets of the present not speak of it? What men are poets who can
    speak of Jupiter if he were like a man, but if he is an immense spinning
    sphere of methane and ammonia must be silent? [Feynmann]
    Ben Morrow, Feb 27, 2007
    #4
  5. doni

    doni Guest

    On Feb 27, 2:09 pm, Ben Morrow <> wrote:
    > This is not a Perl question. The path on the #! line is not used by
    > perl, but by your operating system. In general, there is no way to put
    > any logic into that line, though
    >
    > #!/usr/bin/env perl
    >
    > may do what you want. Note that it will use the perl in your current
    > PATH, which may be a security risk. As others have said, you are much
    > better off arranging for perl to be available as /usr/bin/perl, or
    > writing some sort of installation script that changes the #! line.
    >
    > Ben


    Thanks for your input. I will have an installation script to change
    the #! line.

    Thanks,
    doni
    doni, Feb 27, 2007
    #5
  6. On 2007-02-27 22:09, Ben Morrow <> wrote:
    > Quoth "doni" <>:

    [changing the shebang line depending on uname]
    > As others have said, you are much better off arranging for perl to be
    > available as /usr/bin/perl, or writing some sort of installation
    > script that changes the #! line.


    If you use ExtUtils::MakeMaker or Module::Build, this is done
    automatically at install time.

    hp


    --
    _ | Peter J. Holzer | Es ist ganz einfach ihn zu verstehen, wenn
    |_|_) | Sysadmin WSR | man nur alle wichtigen Worte im Satz durch
    | | | | andere ersetzt.
    __/ | http://www.hjp.at/ | -- Nils Ketelsen in danr
    Peter J. Holzer, Feb 27, 2007
    #6
  7. doni

    Dr.Ruud Guest

    doni schreef:

    > I want to write a program that does check the appropriate system path
    > for perl in FreeBSD and Linux.


    which -a perl

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Mar 5, 2007
    #7
    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. Matthew Thorley

    python uid uname manipultaion/fetching

    Matthew Thorley, Jun 3, 2004, in forum: Python
    Replies:
    2
    Views:
    447
    Phil Frost
    Jun 3, 2004
  2. Replies:
    4
    Views:
    352
    Kai-Uwe Bux
    Jul 3, 2007
  3. Andy B
    Replies:
    0
    Views:
    423
    Andy B
    Apr 19, 2008
  4. Stu

    [ann] uname ruby library

    Stu, Dec 6, 2004, in forum: Ruby
    Replies:
    2
    Views:
    135
  5. Daniel Berger

    [ANN] sys-uname 0.7.0

    Daniel Berger, Jan 11, 2005, in forum: Ruby
    Replies:
    0
    Views:
    79
    Daniel Berger
    Jan 11, 2005
Loading...

Share This Page