[Toybox] Add remaining pwd options
Rob Landley
rob at landley.net
Tue Jan 1 22:41:27 PST 2013
On 01/01/2013 06:49:00 AM, Felix Janda wrote:
> On 12/31/12 at 09:50pm, Rob Landley wrote:
> > On 12/31/2012 10:39:18 AM, Felix Janda wrote:
> > > On 12/30/12 at 05:47pm, Rob Landley wrote:
> > > > On 12/30/2012 05:16:41 AM, Felix Janda wrote:
> > > > > On 12/30/12 at 04:43am, Rob Landley wrote:
> > > > > POSIX contains many surprises. In the section on environment
> > > > > variables it
> > > > > says that $PWD should be set if "pwd -P" was specified. What
> > > happens
> > > > > if an
> > > > > error happens seems unspecified.
> > >
> > > Sorry, this is wrong. It has been changed between SUSV4 and SUSV3.
> > > Now pwd
> > > must not change $PWD. (It would be really nice to have SUSV4 man
> > > pages...)
> >
> > There are susv4 web pages which you can download and pull up with
> > "links" or similar if it really bothers you.
>
> Having something like "man 1p pwd" is just too convenient.
>
> > Trying to beat sane behavior out of bash is not a fruitful endeavor:
> >
> > cd
> > mkdir missing
> > cd missing
> > rmdir ../missing
> > pwd -P
> > cd ..
> > ls
> > echo $PWD
> >
> > I'm not copying that behavior.
>
> Of course, me neither. bash seems still to try to follow the older
> version
> of POSIX, but its version of "pwd -P" seems to be broken in another
> way.
>
>
> Do I understand correctly that in the case that pwd (as a builtin of
> toysh)
> can't determine the path of the current working directory with
> getcwd() it
> should fall back to printing $PWD?
1) The default value is -L, and it only looks at $PWD in -L mode. If
you say pwd -P with no cwd, it should fail.
2) If $PWD is set to a value that the shell wouldn't set it to, it's
discarded and we fall back to -P. Specifically, if it's not an absolute
path, or if it contains . or .. components, it is considered invalid.
3) If $PWD does not point to the current directory, fall back to -P.
What I did was disable #3 in the case where cwd doesn't exist. So the
new rule #3 is:
3) If cwd exists and $PWD doesn't point to it, fall back to -P.
> BTW, in the case that one has deleted and recreated one's current
> working
> directory one could also use "cd ." to get to the new directory.
Good to know. (This means the shell is special casing "." as well as
"..". I need to read the susv4 shell stuff thoroughly, it's been
years...)
> Felix
Rob
1357108887.0
More information about the Toybox
mailing list