Changing directory with a twist

Oleg Broytmann phd at phd.russ.ru
Tue Mar 14 17:59:12 CET 2000


On Tue, 14 Mar 2000, Gaetan Corneau wrote:
> >    What OS? UNIX?
> Sorry: NT and Linux

   Don't know anything about NT. On UNIX (Linux is UN*X too) you need to
pass the name of directory back to shell, and the shell have to be prepared
to get the name and chdir. Example:

in shell:
eval cd "`myprog.py`"
         ^         ^ these are backticks, not apostrophs

in myprog.py:
print "/usr/local/etc"
sys.exit()

   Please note - I am paranoid sysadmin :) so:

1) I do not recommend eval `anyprog.py` - if anyprog.py returns a trojan
shell script you'll be in trouble;

2) I do recomment to wrap the result in double quotes - to pass the output
to cd as 1 parameter, thus you can return a directory name with spaces;
anyway I do not recomment have directory names with special character -
they may be evaluated by eval.

Oleg.
---- 
    Oleg Broytmann      Foundation for Effective Policies      phd at phd.russ.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list