pushd/popd
Carruth, Rusty
Rusty at smartm.com
Mon Oct 13 11:02:49 MST 2014
There is also ‘pushd +<number>’ where the number is an index into the stack. You can say ‘dirs’ to get a list of the shell stack…
As a reminder to anyone confused – remember we are talking about commands to the SHELL. You (usually) are sitting at a command prompt doing this. I regularly have anywhere from 2 to 10 directories on my shell
For example, here is ‘dirs’ from my windows machine in a shell that I have done very little in:
$ dirs
/cygdrive/c/Users/rusty.carruth/Documents ~
And from a linux bos:
rusty at sr-arz-web01 ~/performance_numbers/parser/logs $ dirs
~/performance_numbers/parser/logs ~/performance_numbers/cairoplot-1.1
I have started using pushd/popd in my shell scripts when I need to change to a certain directory (to make the job easier, usually). A lot easier than “set pastdir=`pwd`;cd somewhere ; do_stuff;cd $pastdir” since I seem to get that first set wrong too often.
Also, when writing ‘keyboard scripts’ I use pushd/popd a lot when doing this sort of thing:
for I in `find . –type d` ; do pushd $i ; do_stuff && do_other_stuff_that_only_should_happen_if_stuff_was_ok; popd ; done
Understanding the above ‘command-line (or keyboard) script’ is left as an exercise for the reader ;-)
Rusty
From: plug-discuss-bounces at lists.phxlinux.org [mailto:plug-discuss-bounces at lists.phxlinux.org] On Behalf Of Michael Havens
Sent: Friday, October 10, 2014 1:36 PM
To: Main PLUG discussion list
Subject: Re: pushd/popd
I see. So it is a way to stack directories in your order so you can go in reverse a certain order and save yourself some typing. pushd is strange. if you execute it alone it reverses the last two directories on your stack. I didn't know about 'cd -'; thanks for sharing that with me.
:-)~MIKE~(-:
On Fri, Oct 10, 2014 at 1:10 PM, James Mcphee <jmcphe at gmail.com> wrote:
pushd and popd are stack-oriented. You may notice with cd that you can do "cd -" to go to your previous directory. Think of pushd and popd as a way to store those up. You pushd into various directories, which loads them up on the stack, then popd and you get cd'd back into those directories (in reverse order).
Now, you may be asking yourself "why?". It's just an old way of doing things back when the speed of stack memory meant something. I'm sure someone could figure out an actual use for it, but every time I see it implemented, it's done to be obscure, not because it couldn't be more simply implemented with an array.
On Fri, Oct 10, 2014 at 1:06 PM, Michael Havens <bmike1 at gmail.com> wrote:
what is the difference between pushd and pod and the command cd
:-)~MIKE~(-:
---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss at lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss
--
James McPhee
jmcphe at gmail.com
---------------------------------------------------
PLUG-discuss mailing list - PLUG-discuss at lists.phxlinux.org
To subscribe, unsubscribe, or to change your mail settings:
http://lists.phxlinux.org/mailman/listinfo/plug-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.phxlinux.org/pipermail/plug-discuss/attachments/20141013/1cc28037/attachment.html>
More information about the PLUG-discuss
mailing list