Skip to content

Instantly share code, notes, and snippets.

@shyal

shyal/pushdpopd.sh

Last active Nov 7, 2018
Embed
What would you like to do?
pushd popd example
#!/bin/bash
# we are supposed to be in our home directory
cd
# we make a directory called foo
mkdir foo
# we "cd" into foo, but we remember where we came from
pushd foo
# we create a file called blah
touch blah
# we create a path with two directories
mkdir bar/baz -p
# we "cd" into that path, and we remember where we came from
pushd bar/baz
# we create a file called blah
touch blah
# now we are done working. We need to return to where we were originally, because there might be some more stuff to do.
# to do that, we just pop twice, because we pushed twice. We don't need to "remember" where we came from. We don't need to store that information. That information is stored for us by pushed. So we popd twice, and we're home. Have a beer and be happy.
popd
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.