Skip to content

Instantly share code, notes, and snippets.

@shyal
Last active November 7, 2018 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shyal/50bc46dca23fae724797d30387a0652b to your computer and use it in GitHub Desktop.
Save shyal/50bc46dca23fae724797d30387a0652b to your computer and use it in GitHub Desktop.
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