NetBSD-Bugs archive

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

bin/45390: more sh/$PWD follies



>Number:         45390
>Category:       bin
>Synopsis:       more sh/$PWD follies
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 21 22:15:00 +0000 2011
>Originator:     David A. Holland
>Release:        NetBSD 5.99.49
>Organization:
>Environment:
System: NetBSD macaran 5.99.49 NetBSD 5.99.49 (MACARAN) #8: Mon Apr 11 19:54:18 
EDT 2011 dholland@macaran:/usr/src/sys/arch/amd64/compile/MACARAN amd64
Architecture: x86_64
Machine: amd64

/bin/sh:
     $NetBSD: crt0-common.c,v 1.5 2011/03/07 05:09:09 joerg Exp $
     $NetBSD: crt0.S,v 1.1 2010/08/07 18:01:34 joerg Exp $
     $NetBSD: crti.S,v 1.1 2010/08/07 18:01:35 joerg Exp $
     $NetBSD: crtbegin.S,v 1.2 2010/11/30 18:37:59 joerg Exp $
     $NetBSD: alias.c,v 1.13 2010/10/29 17:04:48 stacktic Exp $
     $NetBSD: cd.c,v 1.41 2011/02/17 15:13:49 pooka Exp $
     $NetBSD: echo.c,v 1.14 2008/10/12 01:40:37 dholland Exp $
     $NetBSD: error.c,v 1.37 2008/10/16 14:36:40 dholland Exp $
     $NetBSD: eval.c,v 1.101 2011/02/17 15:13:49 pooka Exp $
     $NetBSD: exec.c,v 1.42 2008/10/16 15:31:05 dholland Exp $
     $NetBSD: expand.c,v 1.83 2009/11/27 10:50:04 tsutsui Exp $
     $NetBSD: histedit.c,v 1.42 2011/01/07 22:21:56 jmmv Exp $
     $NetBSD: input.c,v 1.44 2011/02/17 15:13:49 pooka Exp $
     $NetBSD: jobs.c,v 1.68 2008/12/21 17:16:11 christos Exp $
     $NetBSD: mail.c,v 1.16 2003/08/07 09:05:33 agc Exp $
     $NetBSD: main.c,v 1.56 2010/02/21 09:54:57 christos Exp $
     $NetBSD: memalloc.c,v 1.29 2008/02/15 17:26:06 matt Exp $
     $NetBSD: miscbltin.c,v 1.38 2009/03/29 01:02:49 mrg Exp $
     $NetBSD: mystring.c,v 1.16 2003/08/07 09:05:35 agc Exp $
     $NetBSD: options.c,v 1.41 2009/01/18 00:30:54 lukem Exp $
     $NetBSD: parser.c,v 1.79 2010/12/13 16:54:04 christos Exp $
     $NetBSD: redir.c,v 1.31 2011/02/17 15:13:49 pooka Exp $
     $NetBSD: show.c,v 1.27 2010/11/14 19:36:07 christos Exp $
     $NetBSD: trap.c,v 1.34 2008/02/15 17:26:06 matt Exp $
     $NetBSD: output.c,v 1.33 2010/08/30 06:27:14 christos Exp $
     $NetBSD: var.c,v 1.39 2008/10/16 14:36:40 dholland Exp $
     $NetBSD: test.c,v 1.37 2008/09/10 19:00:51 christos Exp $
     $NetBSD: kill.c,v 1.26 2009/10/01 09:24:38 spz Exp $
     $NetBSD: syntax.c,v 1.2 2007/12/12 22:55:43 lukem Exp $
     $NetBSD: arith.y,v 1.19 2009/11/13 13:49:09 gson Exp $
     $NetBSD: arith_lex.l,v 1.15 2009/10/29 14:21:40 christos Exp $
     $NetBSD: printf.c,v 1.35 2011/03/15 23:11:49 christos Exp $
     $NetBSD: crtend.S,v 1.1 2010/08/07 18:01:34 joerg Exp $
     $NetBSD: crtn.S,v 1.1 2010/08/07 18:01:35 joerg Exp $

>Description:

Because of kshisms that have been allowed to creep into POSIX, sh
sports some complications pertaining to cd, pwd, and the $PWD
environment variable.

I remember some time ago editing the documentation after a lengthy
argument in tech-userlevel, so I believe the behavior of the program
should be updated to match the man page.

To wit:

 - pwd is supposed to accept both -L and -R options, but the -R option
   is not accepted:
        % mkdir /tmp/foo
        % env PWD= sh -c 'cd /tmp/foo; pwd -R'
        pwd: Illegal option -R
        Exit 2
        % 

 - while cd -L is not supported, cd is supposed to accept the -R
   option, which is the default, but it doesn't:
        % sh -c 'cd -R /'
        cd: Illegal option -R
        Exit 2
        % 

 - cd is supposed to print the name of the directory it changes into
   if it is not the name given, and the shell is interactive, but it
   does not:
        % mkdir /tmp/foo
        % mkdir /tmp/foo/test
        % ln -s test /tmp/foo/link
        % sh -i
        $ cd /tmp/foo/link
        $ /bin/pwd
        /tmp/foo/test
        $ exit
        % 

 - pwd -L is not supposed to print the cached internal value (which is
   related to but separate from $PWD) unless it names the current
   directory. However, at least in some circumstances it will, such as
   this:
        % mkdir /tmp/foo
        % mkdir /tmp/foo/alpha
        % mkdir /tmp/foo/beta
        % env PWD= sh -c 'cd /tmp/foo/beta; mv /tmp/foo/beta 
/tmp/foo/alpha/beta; pwd'
        /tmp/foo/beta
        % 

 - cd is supposed to both change to the named directory and update
   $PWD with it, but it does not always do this correctly:
        % mkdir /tmp/foo
        % mkdir /tmp/foo/alpha
        % mkdir /tmp/foo/beta
        % env PWD= sh -c 'cd /tmp/foo/beta; mv /tmp/foo/beta 
/tmp/foo/alpha/beta; cd ..; echo $PWD'
        /tmp/foo
        % 
   (In this case the internal cached value used by the pwd builtin is also
   incorrectly set to /tmp/foo and then also, as in the previous example,
   incorrectly printed.)


Also, the man page is not explicit about what "update PWD with the
specified directory" actually means if the specified directory is not
absolute. The wording needs to be improved.

Since I wrote that text, I'm allowed to say what I intended, which is
that PWD be updated with the/a name for the specified physical
directory, not that the value of $PWD should be used in preference to
reality when it's wrong, updated relatively, and then used in a
chdir() call. ksh will do the latter in at least some circumstances
but it's clearly broken:
        % mkdir /tmp/foo
        % mkdir /tmp/foo/alpha
        % mkdir /tmp/foo/beta
        % env PWD= ksh -c 'cd /tmp/foo/beta; mv /tmp/foo/beta 
/tmp/foo/alpha/beta; echo $PWD; /bin/pwd; cd ..; echo $PWD; /bin/pwd'
        /tmp/foo/beta
        /tmp/foo/alpha/beta
        /tmp/foo
        /tmp/foo
        % 

>How-To-Repeat:

as above.

>Fix:

don't have time this week, maybe later.




Home | Main Index | Thread Index | Old Index