I am trying to implement my own version of the "cd" command, which presents the user with a list of hard-coded directories to choose from, and the user must enter the number corresponding to the entry in the list. Now the program, named my_cd.py, should effectively "cd" the user into the selected directory. An example of how this should work:
/some/directory
$ my_cd.py
1) ~
2) /bin/
3) /usr
Enter menu selection, or q to quit: 2
/bin
$
I am currently trying to use "cd" os.chdir('dir'). However, this does not work, perhaps because it my_cd.pystarts in its own child process. I tried wrapping the call my_cd.pyin a bash script source with the name my_cd.sh:
#! /bin/bash
function my_cd() {
/path/to/my_cd.py
}
/some/directory
$ . my_cd.sh
$ my_cd
... shows list of dirs, but doesn't 'cd' in the interactive shell
, ? python script?