From be9@be9.ru  Wed May 22 19:10:44 2002
Return-Path: <be9@be9.ru>
Received: from viola.sinor.ru (viola.sinor.ru [217.70.106.9])
	by hub.freebsd.org (Postfix) with ESMTP id 6F80837B40B
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 22 May 2002 19:10:42 -0700 (PDT)
Received: from be9.home.ru (p144.bass7.sinor.ru [217.70.109.144])
	by viola.sinor.ru (8.9.3/8.9.3) with ESMTP id JAA13614
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 23 May 2002 09:10:38 +0700
Received: from unknown (localhost [127.0.0.1])
	by be9.home.ru (8.12.3/8.12.3) with SMTP id g4N2EWcT000670
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 23 May 2002 09:14:34 +0700 (NOVST)
	(envelope-from be9@be9.ru)
Message-Id: <20020523091432.5aa8640b.be9@be9.ru>
Date: Thu, 23 May 2002 09:14:32 +0700
From: oleg dashevskii <be9@be9.ru>
To: FreeBSD-gnats-submit@freebsd.org
Subject: possible bug in /bin/sh: inconsistency between manpage and real program behaviour

>Number:         38442
>Category:       bin
>Synopsis:       possible bug in /bin/sh: inconsistency between manpage and real program behaviour
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    tjr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 22 19:20:01 PDT 2002
>Closed-Date:    Wed Jun 26 01:11:56 PDT 2002
>Last-Modified:  Wed Jun 26 01:11:56 PDT 2002
>Originator:     oleg dashevskii
>Release:        FreeBSD 4.6-PRERELEASE i386
>Organization:
NSU
>Environment:
System: FreeBSD be9.home.ru 4.6-PRERELEASE FreeBSD 4.6-PRERELEASE #1: Wed May 15 10:22:20 NOVST 2002 od@be9.home.ru:/usr/obj/usr/src/sys/BECHO i386


>Description:
	Quoting from `man sh`:

=== q ===
If directory is not found as a subdirectory of the current directory
(and does not begin with ``/'', ``./'', or ``../''), then the
directories listed in the CDPATH variable will be searched for the
specified directory.
=== end q ===

	Now let us check that:

running /bin/sh:

$ cd
$ pwd
/home/od
$ export CDPATH=/
$ echo $CDPATH
/
$ mkdir 9999
$ cd 9999
cd: can't cd to 9999
$ cd ./9999
cd: can't cd to ./9999
$ cd ../od/9999
cd: can't cd to ../od/9999
$ cd ..
/                          <---- and here must be /home, not "/" !!!
$ pwd
/
$ cd /home/od/9999
$ pwd
/home/od/9999		   <---- works with full path
$ export CDPATH=
$ cd
$ cd 9999
$ pwd
/home/od/9999


So, as we can see, CDPATH is preferred over subdirectories in current
directory, as opposed to the words from the manpage.  Even '..' was
substituted as '/..' which is certainly just '/'!


>How-To-Repeat:

	See above. 

>Fix:

	/usr/src/bin/sh/cd.c should be fixed, I guess.

	Possible workaround is to add "." to the CDPATH, that's what I've
	done. If noone is willing to fix that bug in the code, then
	the manpage should be changed to reflect this "bug-o-feature"
	behavior.

	By the way, zsh doesn't suffer from such a problem.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->tjr 
Responsible-Changed-By: tjr 
Responsible-Changed-When: Wed Jun 19 04:11:15 PDT 2002 
Responsible-Changed-Why:  
I'll investigate this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=38442 
State-Changed-From-To: open->patched 
State-Changed-By: tjr 
State-Changed-When: Wed Jun 19 05:07:51 PDT 2002 
State-Changed-Why:  
The current behaviour of sh(1) is correct. I've updated the manual page 
to document the way cd really works. Thanks. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=38442 
State-Changed-From-To: patched->closed 
State-Changed-By: tjr 
State-Changed-When: Wed Jun 26 01:11:26 PDT 2002 
State-Changed-Why:  
Change has been MFC'd. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=38442 
>Unformatted:
