Pushd, popd, dirs for stock SysV.3 Bourne shell

Piercarlo Grandi pcg at cs.aber.ac.uk
Thu Sep 27 01:47:49 AEST 1990


You wwill find appended a small shell script that defines under a stock
System V Bourne shell the pushd, popd, dirs commands of csh(1). They are
trivially adapted to the Korn shell. I have taken care to make them as
robust as possible.

-----------------------------cut here-------------------------------
DIRS=''

# We do a few contortions to ensure correct behaviour
# if directory pathnames contain spaces et similia.
# The things that substitute ~ for $HOME are commented
# out; you may want to comment them in.

cwd()
{
    pwd				# | sed 's|'"$HOME"'/|~/|'
}

chdir()
{
    cd "$1"			# cd `echo "$1" | sed 's|^~/|'"$HOME"'/|`
}

pushd()
{
    CWD="`pwd`"

    case "$1" in

    '')	case "$DIRS" in
	'') echo "directory stack empty"; return 1;;
	esac
	set $DIRS; eval cd "$1"; >/dev/null || return 1
	shift; DIRS="'$CWD' $@"; cwd;;

    *)	chdir "$1" || return 1
	DIRS="'$CWD' $DIRS";;

    esac
    return 0
}

popd()
{
    case "$DIRS" in
    '') echo "directory stack empty"; return 1;;
    esac
    set $DIRS; eval cd "$1"
    shift; DIRS="$*"; cwd
    return 0
}

dirs()
{
    CWD="`pwd`" || return 1
    eval echo "'$CWD' $DIRS"	# | sed 's|'"$HOME"'/|~/|g'
    return 0
}

---------------------------cut here as well----------------------------
--
Piercarlo "Peter" Grandi           | ARPA: pcg%uk.ac.aber.cs at nsfnet-relay.ac.uk
Dept of CS, UCW Aberystwyth        | UUCP: ...!mcsun!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg at cs.aber.ac.uk



More information about the Alt.sources mailing list