From nobody@FreeBSD.ORG Fri Jul  9 08:55:59 1999
Return-Path: <nobody@FreeBSD.ORG>
Received: by hub.freebsd.org (Postfix, from userid 32767)
	id 8B96B14EA4; Fri,  9 Jul 1999 08:55:59 -0700 (PDT)
Message-Id: <19990709155559.8B96B14EA4@hub.freebsd.org>
Date: Fri,  9 Jul 1999 08:55:59 -0700 (PDT)
From: pfeifer@dbai.tuwien.ac.at
Sender: nobody@FreeBSD.ORG
To: freebsd-gnats-submit@freebsd.org
Subject: `cd somewhere` changes current working directory in /bin/sh scripts
X-Send-Pr-Version: www-1.0

>Number:         12578
>Category:       bin
>Synopsis:       `cd somewhere` changes current working directory in /bin/sh scripts
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    sheldonh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul  9 09:00:01 PDT 1999
>Closed-Date:    Mon Jul 19 04:03:59 PDT 1999
>Last-Modified:  Mon Jul 19 04:04:31 PDT 1999
>Originator:     Gerald Pfeifer
>Release:        FreeBSD 3.2-RELEASE i386
>Organization:
>Environment:
FreeBSD polaris.dbai.tuwien.ac.at 3.2-RELEASE FreeBSD 3.2-RELEASE #0:
Tue May 18 04:05:08 GMT 1999     jkh@cathair:/usr/src/sys/compile/GENERIC  i386
>Description:
`man sh` says

   Command Substitution
     Command substitution allows the output of a command to be substituted in
     place of the command name itself.  Command substitution occurs when the
     command is enclosed as follows:

           $(command)

     or (``backquoted'' version):

           `command`

     The shell expands the command substitution by executing command in a sub-
     shell environment and replacing the command substitution with the stan-
     dard output of the command,

yet a `cd /some/where` actually does change the current working
directory of a shell script it occurs in, i.e., apparently it is
not invoked in a sub-shell.

Debian GNU/Linux 2.1 (with bash), Solaris 2.6, AIX 4.1 and DEC OSF1 4.0
behave as expected, see "How to repeat the problem".
>How-To-Repeat:
Run the following script:

  #!/bin/sh

  cd /tmp
  echo .`cd /`.
  pwd  

The expected output (as obtained on Solaris 2.6, Debian GNU/Linux 2.1, 
AIX 4.1 and DEC OSF1 4.0) is as follows
  ..
  /tmp
while FreeBSD 3.2 incorrectly prints
  ..
  /
>Fix:
Replace /bin/sh by bash.

>Release-Note:
>Audit-Trail:

From: Niall Smart <niall@pobox.com>
To: Sheldon Hearn <sheldonh@uunet.co.za>
Cc: hackers@freebsd.org, bugs@freebsd.org
Subject: Re: bin/12578: `` subshell taints PWD
Date: Mon, 12 Jul 1999 18:37:13 +0000

 Sheldon Hearn wrote:
 
 > cd /tmp
 > echo .`cd /`.
 > pwd
 > 
 > Any takers?
 
 The patch appended seems to fix this, I'd like someone familiar
 with sh to review it though, since this may be symptomatic of
 a general problem with command substitution.
 
 > PS: And no, this is not an invitation to chat about the default shell
 >     for the base system. :-)
 
 You're hinting it should be /bin/sh for root, right?
 
 Regards,
 
 Niall
 
 
 *** eval.c~     Mon May 10 16:10:16 1999
 --- eval.c      Mon Jul 12 18:27:44 1999
 ***************
 *** 710,715 ****
 --- 710,716 ----
             && ((flags & EV_EXIT) == 0 || Tflag))
          || ((flags & EV_BACKCMD) != 0
             && (cmdentry.cmdtype != CMDBUILTIN
 +                || cmdentry.u.index == CDCMD
                  || cmdentry.u.index == DOTCMD
                  || cmdentry.u.index == EVALCMD))) {
                 jp = makejob(cmd, 1);
 
 
State-Changed-From-To: open->feedback 
State-Changed-By: sheldonh 
State-Changed-When: Tue Jul 13 03:17:53 PDT 1999 
State-Changed-Why:  
Could you try Niall Smart's patch to src/bin/sh/eval.c and provide 
feedback? 
Responsible-Changed-From-To: freebsd-bugs->sheldonh 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Mon Jul 19 04:02:50 PDT 1999 
Responsible-Changed-Why:  
I'll take this one. 
State-Changed-From-To: feedback->closed 
State-Changed-By: sheldonh 
State-Changed-When: Mon Jul 19 04:03:59 PDT 1999 
State-Changed-Why:  
Committed, thanks! 
>Unformatted:
