4 ms·
It's really handy for scripts too. pushd/popd definitely live up to the word awesome. For interactive use zsh has an option called autopushd that automatically
by sjs 15y ago
It's really handy for scripts too. pushd/popd definitely live up to the word awesome.
For interactive use zsh has an option called autopushd that automatically pushes directories you `cd` to. I never remember to use pushd so it's a nice convenience.
- leviathan 15y agoIt's not just handy for scripts, I think it's imperative in scripts where you want to go in and out of a lot of directories. for i in foo bar baz; do cd $i; #... do something cd ..; done; if "bar" doesn't exist, your cd .. will throw you off your original directory, whereas for i in foo bar baz; do pushd $i; #... do something popd; done; you'll be guaranteed that after "popd" you're back in the right place to start a new iteration.
- phaker 15y agoYou really, really should use 'set -e' which will exit if there are any errors. Otherwise if 'bar' doesn't exist, you'll 'do something' in a wrong directory and frobnicate something you didn't want frobnicated.