Operating System - HP-UX
1832867 Members
2965 Online
110048 Solutions
New Discussion

Re: relative paths - where am I going?

 
SOLVED
Go to solution
Peter Gillis
Super Advisor

relative paths - where am I going?

Hi,I know I am asking a simple question but I reckon I am missing something basic.
opsys = ux 11.00; machine D390

I am in a directory - dirA. (not root directory)
What is the difference when I run:
.(space).profile

and when I run:
./.profile

In other words which .profile am I using? I have issued the above commands, then the 'which .profile' command - both times the result was:
dirA/.profile
I was under the impression that . .profile would be the root directory .profile file and ./.profile was the dirA .profile file. Am I right, or am I totally confused?

Thanks in advance for your help and patience
Maria.
3 REPLIES 3
Patrick Wallek
Honored Contributor
Solution

Re: relative paths - where am I going?

Both commands will access the same .profile, the one in your current directory.

The difference in the commands is that the '.(space).profile' will SOURCE the profile so that all environment variable, etc., are available from your current shell.

The './.profile' will essentially just execute the .profile in a new shell and then exit, so none of the environment variables are available to your current shell.

If you wanted to source the .profile from the root directory (/) you would have to do a '.(space)/.profile'.

Peter Gillis
Super Advisor

Re: relative paths - where am I going?

Thank you heaps, Patrick. You have cleared the fog for me. And your assistance was so clear - excellent. thankyou. Maria.
Darrell Allen
Honored Contributor

Re: relative paths - where am I going?

Hi Maria,

A small correction to the good information Patrick provided...

Whether you preceed .profile with .(space) or not, the .profile to be executed will be the first one found in your search path. It will not look for .profile in your current directory unless the current directory is specified in your $PATH environmental variable and another .profile is not found in a directory listed before your current directory in $PATH.

For example:
echo $PATH
/usr/sbin:/usr/bin:/home/darrella:.
cd /home/maria
ls -a
.profile

If I do ".profile", the shell will search for .profile in /usr/sbin, /usr/bin, /home/darrella, and lastly, my current directory (/home/maria in this example. The search will stop when .profile is found in any of these directories. So if /home/darrella/.profile exists, the shell will try to execute it. If it doesn't exist, the shell will continue the search and try to execute /home/maria/.profile.

I say "try to execute" because that depends on file and directory permissions.

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