I was trying to figure out how to have a child process change the current directory of a parent process. Turns out you can’t quite do that. One thing I guess you could do is export a global variable and then have the parent check that when the child returns, but I decided on another approach. What I do is write a file to ~/bin/errdir that contains a single line in the format:
pushd "/path/to/directory"
I can then source this as a command file after my script has run to change directory into the directory where the last erroneous file was encountered with the command:
$ . errdir
When I’m finished I can just type ‘popd’ to return myself to wherever I was before I changed into the error directory.