I'd like to be able to know mid-working what directory a child process started in.

Here I'm in a Bash session, I start a dash session and I'd like to know where did dash start (in the example it would be /home).

$ echo $PWD
$ dash
$ cd .. && echo $PWD
/   #Here I was hoping it would print /home
echo $PWD
/home   #And the shell somehow knew where to get back to

How do I do this?

  • This answer solves it unix.stackexchange.com/a/74253/346863 but the question isn't a duplicate. – exiting Apr 12 at 19:24
  • If you don't call cd .. first, then it would print /home. – ctrl-alt-delor Apr 12 at 19:31
  • @ctrl-alt-delor Yes, you missed my point. I start dash, I do a bunch of stuff and change directories a bunch of times, I want to know where the process as initiated. – exiting Apr 12 at 19:41
  • 2
    Add initial_pwd="$PWD" to the start. Note this is not the same as the directory containing the script. – ctrl-alt-delor Apr 12 at 19:42
  • Alas that doesn't help me because the child session I'm in always starts in the home directory, regardless of where the child started. I really need to know where the child shell initiated. – exiting Apr 12 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.