Unix C Shell Question...previous working directory

NaturalChiller

Senior member
Jun 27, 2001
292
0
0
Is there a way in csh to jump from the current directory (ie pwd) to the path of the previous working directory? Without using pushd popd and dirs?
 

baoytl

Senior member
Aug 14, 2000
330
0
76
You mean something like

cd ..

?

edit:
I forgot. This is in my .cshrc file. I'm not sure if this is what you wanted.

if ( $?tcsh ) then
alias cd 'set oldwd=$cwd;chdir \!*; set prompt="%m% "'
alias po 'popd \!*; set prompt="%m% "'
alias pu 'pushd \!*; set prompt="%m% "'
if ( $?prompt ) set prompt="%m% "
bindkey ^w backward-delete-word
unset autologout
# for tcsh within emacs
if $?EMACS unset edit
else
set lochost = `hostname | awk -F. '{print $1}'`
alias cd 'cd \!*; set prompt="$lochost% "'
alias po 'popd \!*; set prompt="$lochost% "'
alias pu 'pushd \!*; set prompt="$lochost% "'
if ( $?prompt ) set prompt="$lochost% "
endif
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
.. is the parent directory, not the last directory visited.

Maybe make a function called cd that does pushd and directs the output to /dev/null. Unless I'm missing something, I think that does what you want. And then alias popd to whatever else, also throwing away output. Not sure about csh, but in sh:



death@two ~ % cd() {
> pushd $* >/dev/null
> }
death@two ~ % alias back='popd >/dev/null'
death@two ~ % cd /tmp
death@two /tmp % cd /etc
death@two /etc % back
death@two /tmp % back
death@two ~ %