home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
1
/
1866
< prev
next >
Wrap
Internet Message Format
|
1990-12-28
|
2KB
From: pcg@cs.aber.ac.uk (Piercarlo Grandi)
Newsgroups: comp.unix.shell,alt.sources
Subject: Pushd, popd, dirs for stock SysV.3 Bourne shell
Message-ID: <PCG.90Sep26164749@odin.cs.aber.ac.uk>
Date: 26 Sep 90 15:47:49 GMT
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@nsfnet-relay.ac.uk
Dept of CS, UCW Aberystwyth | UUCP: ...!mcsun!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk