Operating System - HP-UX
1834187 Members
2939 Online
110064 Solutions
New Discussion

Re: PATH variable not being used

 
Preet Dhillon
Advisor

PATH variable not being used

I have Perl installed in /opt/perl5/bin. This path is appended to the user's PATH variable in his .profile as follows :

PATH=$PATH:/opt/perl5/bin;export PATH

When he logs in and echoes $PATH, he sees the following :

/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/nettladm/bin:/opt/upgrade/bin:/usr/b
in/X11:/usr/contrib/bin/X11:/opt/hpnp//bin:/opt/omni/bin:/opt/hparray/bin:/opt/p
red/bin:/home/russg:.:/opt/perl5/bin

BUT when he enters 'which perl' he gets this :

no perl in /bin /usr/bin

and cannot run any perl scripts. Why can't he find perl when it's in his PATH ?

Many thanks in advance.
Nothing succeeds like excess
9 REPLIES 9
Thierry Poels_1
Honored Contributor

Re: PATH variable not being used

hi,

is it a batch program you are running (through crontab) ??
/bin & /usr/bin is the default path when executing cron jobs; you have to add the necessary environment variable explicitely in your script (by sourcing your .profile, or another settings script)

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Victor BERRIDGE
Honored Contributor

Re: PATH variable not being used

Hi,
I agree with Thierry it can be a batch bad setting, or a reset of the environment by an application or some custom profile called later, are you sure you get this straight after logging in? if so whats after you PATH=..., in the .profile?


Regards
Victor
Thierry Poels_1
Honored Contributor

Re: PATH variable not being used

Hi again,

another option is to put following line on top of your perl script:

#! /opt/perl5/bin/perl

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Darrell Allen
Honored Contributor

Re: PATH variable not being used

Often problems like this have a more simple explanation and we tend to overlook the simple for the complex. Your user must have reset his path after logging in and before running the which. The which output indicates which only checked /bin and /usr/bin. Could your user have reset his path in another script or by su'ing?
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
harry d brown jr
Honored Contributor

Re: PATH variable not being used

From the man pages of "which":

which's information may be incorrect because it is unaware of any path or alias changes that have occurred in the current shell session.

Try using whereis or whence, although the results are a little strange. Check this out:

# whence perl
/usr/bin/perl
# which perl
/bin/perl
# whereis perl
perl: /usr/bin/perl /usr/local/bin/perl5.003 /usr/local/bin/perl /usr/local/bin/perl5.004 /usr/local/lib/perl /usr/local/lib/perl5.004 /usr/contrib/bin/perl /opt/perl5/bin/perl /usr/local/man/man1/perl.1 /opt/perl5/man/man1/perl.1
# ls -l /bin|grep perl
# ls -Ll /bin|grep perl
-r-xr-xr-x 3 root sys 856217 Feb 12 1998 perl
# ls -l /|grep bin
lr-xr-xr-t 1 root sys 8 May 12 1997 bin -> /usr/bin
dr-xr-xr-x 16 bin bin 12288 Aug 7 18:27 dev
drwxrwxr-x 62 bin bin 2048 Aug 21 16:41 opt
dr-xr-xr-x 12 bin bin 3072 Jul 16 07:57 sbin
dr-xr-xr-x 4 bin bin 1024 Aug 7 18:00 stand



Live Free or Die
harry d brown jr
Honored Contributor

Re: PATH variable not being used

Also, make sure the permissions on perl are set to have execution for everyone.

chmod a+x perl
Live Free or Die
Sanjay_6
Honored Contributor

Re: PATH variable not being used

It seems which will look up a file in your path only if you have the execute permission for that command. It will return with a no found message even if the file is present in you path and you don't have the execute permission for that.

So like harry has advised set the execute permission on that file. Then no matter where you specify the path in you path variable, which should return with the right output.

Hope this helps

Thanks
Darrell Allen
Honored Contributor

Re: PATH variable not being used

Hi again,

From your post:

BUT when he enters 'which perl' he gets this :
no perl in /bin /usr/bin

When I run which and a file is not found, which lists each directory in my path. The above indicates only /bin and /usr/bin are in the user's path. I still wonder if the path was changed after being set in .profile and before the which command was run.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
MANOJ SRIVASTAVA
Honored Contributor

Re: PATH variable not being used

Hi Preet


Try this

export PATH=/opt/perl5/bin:$PATH , this should work.

Manoj Srivastava