I'm writing a shell script that needs to cd
to some location. Is there any way to get back to the previous location, that is, the location before cd
was executed?
You can simply do
cd -
that will take you back to your previous location.
Some shells let you use pushdir/popdir commands, check out this site. You may also find this SO question useful.