symbolic link question

Steven W. Orr steveo at syslang.net
Tue Dec 3 16:12:13 EST 2002


On Tue, 3 Dec 2002, Bob Bell wrote:

=>    Yes, this is your shell keeping track of how you got to where you
=>are (your 'logical path').  This is usually also reflected in the PWD
=>environment variable.  In bash and ksh, you can use 'pwd -P' to get your
=>real path.  Or, you can run /bin/pwd instead of the shell builtin.  This
=>is also reflected with getcwd().
=>
=>P.S. Please set your mail to wrap long lines.
Ok. We've beaten this one to death, except for one small thing:

It's sort of fascinating how the whole pwd thing works in the first place. 
Remember that there is no system call in Unix to tell you what your 
current working directory is.

The (simplified) algorithm goes something like this.

1. Read the current directory and see which entry has the same name as '.'

2. cd ..

keep on doing these two steps and accumulate the path as you go up till 
you hit Inode 1 for the root of the filesystem. Keep on hacking if you're 
in a subsystem or an nfsmount. 

When you're all done, cd back to where you came from.

This is a lot of work just to calculate where you are. But I guess noone 
has ever done better.

-- 
-Time flies like the wind. Fruit flies like a banana. Stranger things have -
-happened but none stranger than this. Does your driver's license say Organ
-Donor?Black holes are where God divided by zero. Listen to me! We are all-
-individuals! What if this weren't a hypothetical question? steveo at syslang.net




More information about the gnhlug-discuss mailing list