home *** CD-ROM | disk | FTP | other *** search
- 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
-