[comp.unix.wizards] How to clear directory stack in csh

roy@phri.UUCP (Roy Smith) (05/16/88)

	Is there any way to clear the directory stack in csh without doing
popd?  I did essentially the following recently:

# cd /
# mount /dev/ndl7 /mnt
# pushd /mnt/etc
# pushd
# umount /mnt
# popd      <-- this gave an "invalid directory" or somesuch message.

	The problem was that my directory stack was "/ /mnt/etc".  I was
allowed to umount /mnt because while /mnt/etc was in my dirstack because it
wasn't actually the current directory of any proces, but I couldn't clear
the dirstack because a popd would try to cd back to /mnt/etc which no
longer existed.  Having a bogus directory at the bottom of my dirstack
doesn't actually do any harm, but it was annoying that I couldn't find any
way to get rid of it without exiting the shell.
-- 
Roy Smith, System Administrator
Public Health Research Institute
455 First Avenue, New York, NY 10016
{allegra,philabs,cmcl2,rutgers}!phri!roy -or- phri!roy@uunet.uu.net

roy@phri.UUCP (Roy Smith) (05/16/88)

	In the referenced article, I asked how to get an item of csh's
dirstack with actually chdir(2)ing to it.  Chris Torek mailed me the answer
already (it's "popd +1") and I'm sure I'll get deluged with many many more
of the same.  I know, I know, RTFM.  I did RTFM but I guess I never noticed
that.  Let's see, how long have I been using csh?  4, 5 years?  Hmm...
-- 
Roy Smith, System Administrator
Public Health Research Institute
455 First Avenue, New York, NY 10016
{allegra,philabs,cmcl2,rutgers}!phri!roy -or- phri!roy@uunet.uu.net

mark@comp.vuw.ac.nz (Mark Davies) (05/17/88)

In article <3269@phri.UUCP> roy@phri.UUCP (Roy Smith) writes:
>                                     ..., but I couldn't clear
>the dirstack because a popd would try to cd back to /mnt/etc which no
>longer existed.  Having a bogus directory at the bottom of my dirstack
>doesn't actually do any harm, but it was annoying that I couldn't find any
>way to get rid of it without exiting the shell.

popd +1 will remove the first entry in the directory stack (given current
directory is the 0th entry) so if you have a stack that was
	"/ /mnt/etc"
popd +1 will leave it as "/" and since this does not involve changing
directory it doesn't matter that /mnt/etc no longer exists. (This works on
all machines I have access to, Pyramid, Sun, 4.3BSD Vaxen).

mark
-- 
Domainised:  mark@comp.vuw.ac.nz	Bang form: ...!uunet!vuwcomp!mark

schaefer@ogcvax.ogc.edu (Barton E. Schaefer) (05/17/88)

In article <phri.3269> roy@phri.UUCP (Roy Smith) writes:
} 
} Is there any way to clear the directory stack in csh without doing popd?

No, but there's a way to do popd without causing the csh to change to the
directory being popped.

} 	The problem was that my directory stack was "/ /mnt/etc".  I was
} allowed to umount /mnt because while /mnt/etc was in my dirstack because it
} wasn't actually the current directory of any proces, but I couldn't clear
} the dirstack because a popd would try to cd back to /mnt/etc which no
} longer existed.

To remove a bogus directory from the stack, use

	popd +N

where N is the stack position of the bogus directory.  Position 0 (zero) is
the top of the stack.  In the example above,

	% dirs
	/ /mnt/etc
	% popd +1
	/
	%

For those interested, pushd can also take a +N argument, which rotates the
directory stack N positions.

} Roy Smith, System Administrator
} Public Health Research Institute
} 455 First Avenue, New York, NY 10016
} {allegra,philabs,cmcl2,rutgers}!phri!roy -or- phri!roy@uunet.uu.net

-- 
Bart Schaefer			CSNET	schaefer@cse.ogc.edu
				UUCP	...{tektronix,verdix}!ogcvax!schaefer
    Hobbes:  "How come we play war and not peace?"
    Calvin:  "Too few role models."