1*d90bee97SLionel Sambuc# $NetBSD: pushd,v 1.7 1995/05/11 21:31:15 christos Exp $ 2*d90bee97SLionel Sambuc# Copyright (c) 1991, 1993 3*d90bee97SLionel Sambuc# The Regents of the University of California. All rights reserved. 4*d90bee97SLionel Sambuc# 5*d90bee97SLionel Sambuc# This code is derived from software contributed to Berkeley by 6*d90bee97SLionel Sambuc# Kenneth Almquist. 7*d90bee97SLionel Sambuc# 8*d90bee97SLionel Sambuc# Redistribution and use in source and binary forms, with or without 9*d90bee97SLionel Sambuc# modification, are permitted provided that the following conditions 10*d90bee97SLionel Sambuc# are met: 11*d90bee97SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 12*d90bee97SLionel Sambuc# notice, this list of conditions and the following disclaimer. 13*d90bee97SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 14*d90bee97SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 15*d90bee97SLionel Sambuc# documentation and/or other materials provided with the distribution. 16*d90bee97SLionel Sambuc# 3. All advertising materials mentioning features or use of this software 17*d90bee97SLionel Sambuc# must display the following acknowledgement: 18*d90bee97SLionel Sambuc# This product includes software developed by the University of 19*d90bee97SLionel Sambuc# California, Berkeley and its contributors. 20*d90bee97SLionel Sambuc# 4. Neither the name of the University nor the names of its contributors 21*d90bee97SLionel Sambuc# may be used to endorse or promote products derived from this software 22*d90bee97SLionel Sambuc# without specific prior written permission. 23*d90bee97SLionel Sambuc# 24*d90bee97SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25*d90bee97SLionel Sambuc# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26*d90bee97SLionel Sambuc# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27*d90bee97SLionel Sambuc# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28*d90bee97SLionel Sambuc# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29*d90bee97SLionel Sambuc# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30*d90bee97SLionel Sambuc# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31*d90bee97SLionel Sambuc# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32*d90bee97SLionel Sambuc# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33*d90bee97SLionel Sambuc# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34*d90bee97SLionel Sambuc# SUCH DAMAGE. 35*d90bee97SLionel Sambuc# 36*d90bee97SLionel Sambuc# @(#)pushd 8.2 (Berkeley) 5/4/95 37*d90bee97SLionel Sambuc 38*d90bee97SLionel Sambuc# pushd, popd, and dirs --- written by Chris Bertin 39*d90bee97SLionel Sambuc# Pixel Computer Inc. ...!wjh12!pixel!pixutl!chris 40*d90bee97SLionel Sambuc# as modified by Patrick Elam of GTRI and Kenneth Almquist at UW 41*d90bee97SLionel Sambuc 42*d90bee97SLionel Sambucpushd () { 43*d90bee97SLionel Sambuc SAVE=`pwd` 44*d90bee97SLionel Sambuc if [ "$1" = "" ] 45*d90bee97SLionel Sambuc then if [ "$DSTACK" = "" ] 46*d90bee97SLionel Sambuc then echo "pushd: directory stack empty." 47*d90bee97SLionel Sambuc return 1 48*d90bee97SLionel Sambuc fi 49*d90bee97SLionel Sambuc set $DSTACK 50*d90bee97SLionel Sambuc cd $1 || return 51*d90bee97SLionel Sambuc shift 1 52*d90bee97SLionel Sambuc DSTACK="$*" 53*d90bee97SLionel Sambuc else cd $1 > /dev/null || return 54*d90bee97SLionel Sambuc fi 55*d90bee97SLionel Sambuc DSTACK="$SAVE $DSTACK" 56*d90bee97SLionel Sambuc dirs 57*d90bee97SLionel Sambuc} 58*d90bee97SLionel Sambuc 59*d90bee97SLionel Sambucpopd () { 60*d90bee97SLionel Sambuc if [ "$DSTACK" = "" ] 61*d90bee97SLionel Sambuc then echo "popd: directory stack empty." 62*d90bee97SLionel Sambuc return 1 63*d90bee97SLionel Sambuc fi 64*d90bee97SLionel Sambuc set $DSTACK 65*d90bee97SLionel Sambuc cd $1 66*d90bee97SLionel Sambuc shift 67*d90bee97SLionel Sambuc DSTACK=$* 68*d90bee97SLionel Sambuc dirs 69*d90bee97SLionel Sambuc} 70*d90bee97SLionel Sambuc 71*d90bee97SLionel Sambucdirs () { 72*d90bee97SLionel Sambuc echo "`pwd` $DSTACK" 73*d90bee97SLionel Sambuc return 0 74*d90bee97SLionel Sambuc} 75