tech-userlevel archive

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

$OLDPWD



This makes sh(1) set $OLDPWD as explained in:
http://pubs.opengroup.org/onlinepubs/007904875/utilities/cd.html

(The manpage has to be updated too.)

Index: bin/sh/cd.c
===================================================================
RCS file: /cvsroot/src/bin/sh/cd.c,v
retrieving revision 1.41
diff -u -r1.41 cd.c
--- bin/sh/cd.c 17 Feb 2011 15:13:49 -0000      1.41
+++ bin/sh/cd.c 10 Jun 2011 00:32:16 -0000
@@ -264,9 +264,10 @@
                curdir = NULL;
                getpwd(1);
                INTON;
-               if (curdir)
+               if (curdir) {
+                       setvar("OLDPWD", prevdir, VEXPORT);
                        setvar("PWD", curdir, VEXPORT);
-               else
+               } else
                        unsetvar("PWD", 0);
                return;
        }
@@ -297,6 +298,7 @@
                ckfree(prevdir);
        prevdir = curdir;
        curdir = savestr(stackblock());
+       setvar("OLDPWD", prevdir, VEXPORT);
        setvar("PWD", curdir, VEXPORT);
        INTON;
 }
@@ -325,6 +327,7 @@
        else
                find_curdir(0);
 
+       setvar("OLDPWD", prevdir, VEXPORT);
        setvar("PWD", curdir, VEXPORT);
        out1str(curdir);
        out1c('\n');


Home | Main Index | Thread Index | Old Index