# pwd with sh won't give logical path



## izotov (Oct 18, 2011)

Hi,
pwd that works fine with tcsh won't give the logical path with sh. Why? How could I get the logical path with sh?

The strange behaviour:

```
/tmp > uname -a
FreeBSD freebsd73 7.3-RELEASE-p2 FreeBSD 7.3-RELEASE-p2 #0: Mon Jul 12 19:23:19 UTC 2010
root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
/tmp > mkdir physical
/tmp > ln -s physical/ logical
/tmp > cd logical
/tmp/logical > /bin/pwd -L
/tmp/logical
/tmp/logical > sh
$ /bin/pwd -L
/tmp/physical
```


----------



## bigearsbilly (Oct 18, 2011)

I think it's because you change shell in the middle.
A little bug maybe?

It works if you cd out first...

```
[billy@elmer:0]$ pwd -P
/tmp/p/physical
[billy@elmer:0]$ pwd -L
/tmp/q/logical
```


----------



## izotov (Oct 18, 2011)

bigearsbilly said:
			
		

> It works if you cd out first...


Yes.
But the problem is even worse if I try to obtain the logical path in a shell script. Even if I change dirs in sh and then start the shell script pwd -L in the script still gives wrong results.
About cd-ing in the script: the script does not know the name of the link (that is what I want to obtain it from a command) so no step further from here.


----------



## kpa (Oct 18, 2011)

Are you sure that /bin/sh keeps the value of PWD environment variable at its start up? If it somehow resets that variable (custom .profile?) it would explain your problem. I couldn't reproduce this on FreeBSD 9.0 RC1.


----------



## izotov (Oct 19, 2011)

kpa said:
			
		

> Are you sure that /bin/sh keeps the value of PWD environment variable at its start up? If it somehow resets that variable (custom .profile?) it would explain your problem. I couldn't reproduce this on FreeBSD 9.0 RC1.


I removed my stock .profile but still the same. You may be right that $PWD is overwritten somehow but I can not find where.
Could not reproduce on 9.0-BETA3 either.


----------



## oops (Oct 19, 2011)

Can you try to apply r206759?


----------



## izotov (Oct 19, 2011)

oops said:
			
		

> Can you try to apply r206759?


Thanks! This one solved it!


----------

