Choosing the path based on the system "uname" command

D

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 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
 
P

Paul Lalli

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
 
J

J. Gleixner

doni said:
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.
 
B

Ben Morrow

Quoth "doni said:
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
 
D

doni

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
 
P

Peter J. Holzer

[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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top