Skip site navigation (1)Skip section navigation (2)
Date:      Fri,  9 Jul 1999 08:55:59 -0700 (PDT)
From:      pfeifer@dbai.tuwien.ac.at
To:        freebsd-gnats-submit@freebsd.org
Subject:   bin/12578: `cd somewhere` changes current working directory in /bin/sh scripts
Message-ID:  <19990709155559.8B96B14EA4@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         12578
>Category:       bin
>Synopsis:       `cd somewhere` changes current working directory in /bin/sh scripts
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jul  9 09:00:01 PDT 1999
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990709155559.8B96B14EA4>