pushd and popd for ksh

For a script I need the pushd and popd internals commonly used in bash csh and friends. Since ksh does not come with these two I did it myself:

function pushd {
  cd $1
  DIR=`pwd`
  export __DIRSTK="$DIR":$__DIRSTK
}
function popd {
  DIR=`echo $__DIRSTK|cut -f 2 -d:`
  if test "$DIR" != "" 
    then cd $DIR;
    else cd -  
  fi
  export __DIRSTK=`echo $__DIRSTK|cut -f 2- -d:`
}

Code on this site is licensed under a 2 clause BSD license, everything else unless noted otherwise is licensed under a CreativeCommonsAttribution-ShareAlike3.0UnportedLicense