1

We can change the current directory in the shell :

username@hostname:~/f1$ cd ~/f2
username@hostname:~/f2$ 

is it possible to write a python (v2.7 and / or v3) which changes the current directory to one programatically determined ?

E.g.

username@hostname:~/f1$ python change_dir.py
username@hostname:~/f2$ 
2
  • 5
    It is not possible; a child process cannot change the environment of its parent. That's why cd is a shell built-in command. Commented Oct 20, 2019 at 19:49
  • Agree, it is just impossible. Commented Oct 20, 2019 at 22:08

1 Answer 1

1

As chepner and Sraw correctly said, a child process cannot change the current directory of its parent. So, what you can do is to let the Python program output the desired directory and use this output in a cd command:

cd `python print_dir.py`
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.