bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using absolute path instead of relative path on all operations


From: Eric Blake
Subject: Re: Using absolute path instead of relative path on all operations
Date: Sat, 07 Feb 2009 07:25:08 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.19) Gecko/20081209 Thunderbird/2.0.0.19 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Till Halbach on 2/6/2009 4:23 AM:
> I have come over something which I think of as a bug, but you might
> disagree.

Not a bug; POSIX requires this behavior.

> 
> Consider
> $ cd
> $ mkdir dir1 dir2
> $ cd dir1
> $ ln -s ../dir2 link
> $ cd link
> $ pwd
> gives $HOME/dir1/link
> but
> $ ls ..
> lists $HOME instead of dir1.

That is because cd and pwd have two different behaviors, both mandated by
POSIX - physical (-P), which behaves like the getpwd system call, and
logical (-L), which remembers how you got to the current location; POSIX
also states that if neither -P nor -L is given, then -L should be assumed.
 cd is always a shell builtin (there is no other way to implement it),
while pwd is typically a shell builtin in addition to being provided by
coreutils.  Coreutils does not yet implement pwd -L or -P, and always
behaves as if -P had been specified, but that feature has been requested
frequently over the years (in part because it means coreutils does not
obey POSIX in this regards).  In the meantime, since you did not give
absolute paths to pwd, you probably got the shell's builtins, which both
behave logically; hence your listing of pwd returning $HOME/dir1/dir2.

But physical vs. logical paths only make sense in a limited number of
settings, such as cd and pwd.  Most applications always behave physically,
including ls.  This is due to the leaky abstraction caused by having two
means of tracking current location in the shell, but only one means of
tracking it once you leave the shell.  If it bothers you that much, then
add an alias or shell function to supply the -P argument to your shell's
cd and pwd commands.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkmNmcQACgkQ84KuGfSFAYCtQQCeKHkZngohmTdu3w30O8sS9MYc
ISUAoJEtBLgxCmaYBUiGRulfj80nLo6/
=Rh78
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]