Re: OLDPWD unset when bash starts
Thanks, Chet! From: Chet Ramey To: John Wiersba ; "bug-bash@gnu.org" Cc: chet.ra...@case.edu Sent: Thursday, November 26, 2015 12:41 PM Subject: Re: OLDPWD unset when bash starts On 11/18/15 2:44 PM, John Wiersba wrote: > Why does bash clear OLDPWD when a child script is started? Because a new shell does not have a `previous working directory'. It's supposed to be set by cd, and if you haven't executed cd, you don't have one. It seems reasonable to inherit OLDPWD if it names a directory, in the same way that the shell inherits PWD if it names the current directory, so we'll try that for the next bash version. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/
OLDPWD unset when bash starts
From: jrw32...@yahoo.com To: bug-bash@gnu.org,b...@packages.debian.org Subject: OLDPWD unset when bash starts Configuration Information [Automatically generated, do not change]: Machine: x86_64 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='l$ uname output: Linux john-mint-mate-17 3.13.0-37-generic #64-Ubuntu SMP Mon Sep $ Machine Type: x86_64-pc-linux-gnu Bash Version: 4.3 Patch Level: 11 Release Status: release Description: Why does bash clear OLDPWD when a child script is started? OLDPWD is exported and passed to any children, but bash apparently clears OLDPWD whenever a child script is started: Can bash be fixed to preserve the value of any OLDPWD in its initial environment, like it does with PWD? This appears to happen on all 3.x and 4.x versions of bash. Repeat-By: $ cd /etc $ cd $ perl -e 'print "<$ENV{OLDPWD}>\n"' $ ksh -c 'echo "<$OLDPWD>"' $ bash -c 'echo "<$OLDPWD>"' <>
OLDPWD unset when bash starts
Why does bash clear OLDPWD when a child script is started? OLDPWD is exported and passed to any children, but bash apparently clears OLDPWD whenever a child script is started: $ cd /etc $ cd $ perl -e 'print "<$ENV{OLDPWD}>\n"' $ ksh -c 'echo "<$OLDPWD>"' $ bash -c 'echo "<$OLDPWD>"' <> $ uname -a Linux myserver 2.6.32-504.8.1.el6.x86_64 #1 SMP Fri Dec 19 12:09:25 EST 2014 $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.5 (Santiago) $ bash --version | head -1 GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu) Can bash be fixed to preserve the value of any OLDPWD in its initial environment, like it does with PWD? Thanks! -- John Wiersba