user1092042
user1092042

Reputation: 1295

Setting the path in a perl program

I have a bluehost server setup and am trying to set the path in my perl program

 print "Content-type: text/html\n\n";
    my $output=`export PATH=\${PATH}:/usr/local/jdk/bin`;
    my output1=`echo \$PATH`;
    print $output1;

However it stil prints only the orginal $PATH. The /usr/local/jdk does not get added. Can anyone tell me what i am doing wrong?

Upvotes: 8

Views: 22232

Answers (2)

Gonen
Gonen

Reputation: 4075

Please note that ikegami's answer will only set the path in your local Perl-script, and will NOT change it for the shell that called your Perl script.

If you wish to change the path in the shell environment, so the next programs you run will also benefit from this change, you will have to use 'source' or "dot-space" sequence, or better yet - have this change to the path done in '.bashrc' or '.login' files.

Upvotes: 3

ikegami
ikegami

Reputation: 386676

You are creating a shell, executing a shell command that sets an environment variable in the shell, then exiting the shell without doing anything with the environment variable. You never changed perl's environment. That would be done using

local $ENV{PATH} = "$ENV{PATH}:/usr/local/jdk/bin";

Kinda weird to add to the end of the path, though.

Upvotes: 13

Related Questions