|
pushd and popd
On every programming course, you're taught never to use the goto statement even if the language has one available, as you're creating spaghetti code that's hard to follow and maintain. I agree with the sentiment.
So .... why, oh why, .... when you're navigating around directories at a command prompt do you use the cd command - it's the shell's equivalent of directory goto as it leaves you jumping away from your current directory, and not leaving a return address for when you want to go back.
Have you come across pushd and popd? When you "pushd" to a directory, you save away on a stack the name of the directory you're moving from; when you "popd" you return. Simple, effective, ang great when you want to pay a temporary visit to a remote directory in a Unix or Linux shell.
P.S. They're supported in Microsoft's Windows XP too! (written 2004-10-05 06:54:00)
| Commentator | says ... | | Bruce James: | Surely in a Bash shell or another shell that supports it.. On my Solaris 9...
bash: yes
ksh: no
bourne: no
csh: yes
tcsh: yes
pfcsh: yes
jsh: no
pfsh: no
zsh: yes (comment added 2004-10-05 14:06:13) | | gje: | Fair comment. I'm not too familiar with jsh and pfsh ... and the bourne shell really has nothing for interaction.
Ksh calls for some comment. It *is* failrly heavily used and doesn't have a native pushd / popd. If you
alias 'popd=cd $OLDPWD'
then you can use cd to get to a new directory and popd back again - bit rough and ready (and just one level deep) but still a jump and return structure if you need one. (comment added 2004-10-05 14:19:37) | | Custard: | True, personally never come across pfsh,jsh or pfcsh before, but they appeared in 'man shells' on my Sol 9 machine. Quite a comprehensive list I thought. Shame tclsh and wish aren't there as standard, but I guess Sun are still smarting from the SunScript debacle.
For a single level popd, you can also 'cd -' which takes you back to where you came from. I use that one all the time. And sometimes if I need 2 levels, I just run another shell.
My fave shells are bash then ksh, and I'd say that ksh is probably the most common of the most fully featured shells, and csh the most broken and advised-against-scripting for.
But bash is appearing more and more on other systems now.
Of course bourne (sh) is still the lowest common denominator if you need to write a script to run across platforms..
b
(sits back and waits for the flames ;-) (comment added 2004-10-06 13:54:24) |
Associated topics are indexed under A101 - Web Application Deployment - Linux -An Introduction For Users
Some other Articles
Domain Registry of AmericaTelephone systemsLearning to program inIt's just not cricketpushd and popdvi - full circleOn Customer ServiceComparators in Linux and UnixRed Luas - early life and timesJohn Toner
|
2258 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46 at 50 posts per page
This is a page archived from The Horse's Mouth at
http://www.wellho.net/horse/ -
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. Please check back via
our main site for current courses,
prices, versions, etc - any mention of a price in "The Horse's Mouth"
cannot be taken as an offer to supply at that price.
Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).
|
|