[Toybox] Add remaining pwd options

Rob Landley rob at landley.net
Sat Jan 12 21:33:09 PST 2013


On 01/10/2013 02:25:13 PM, Felix Janda wrote:
> On 01/02/13 at 12:41am, Rob Landley wrote:
> > 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.
> 
> Thanks for the clarification.
> 
> Your version of 3) depends on whether pwd is builtin or not. Do you  
> mean
> something like "If getcwd() fails ..."?

cwd is what getcwd() returns. $PWD is an environment variable.

> > > 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...)
> 
> The susv4 page special cases "." and ".." a bit, but it seems to me  
> only
> in the $CDPATH handling. Ah, I see that you don't care about $CDPATH  
> from
> the about page.

$CDPATH and $PWD are separate.

> Then I think one can leave out step 5 on susv4's page on
> cd, and "cd ." is no more special than "cd dir"; it does a chdir to  
> "$PWD/."
> or "$PWD/dir" respectively and then updates $PWD to its canonical  
> form. (and
> modifies $OLDPWD also if necessary)

Um, steps 4 and 8 are the ones that say cd . and .. are special?

> Another interesting situation is if your current directory "/dir" has  
> been
> moved to "/olddir" and say "/dir" has been recreated. Then "cd ."  
> will move
> you to new directory whereas "cd $(pwd -P)" will preserve your cwd  
> and fix up
> $PWD. (at least for a shell behaving posixly correct)

Preserving the cwd is what I wanted to do, yes.

> Imagine the same situation but with "/dir" not being recreated after  
> being
> moved. Then "cd ." should fail according to susv4 since "$PWD/." =  
> "/dir/.",
> which does not exist. Would you like to have "cd ." behave the same as
> "cd $(pwd)" in this case? Bash does this if not in POSIX mode.  
> Busybox ash
> doesn't do this and for some reason even "cd $(pwd)" fails.

I want the great mass of existing shell scripts to work, which means  
reproducing historical behavior. Posix is (mostly) a reasonable  
consensus documentation of historical behavior.

> Felix

Rob
 1358055189.0


More information about the Toybox mailing list