Last active
November 7, 2018 18:10
-
-
Save shyal/50bc46dca23fae724797d30387a0652b to your computer and use it in GitHub Desktop.
pushd popd example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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