getcwd() is faulty when in a programmed launched by abspath

174 views Asked by At

Error

When an alias of python command runs on a file defined with an absolute path, its getcwd() becomes faulty, i.e. it doesn't represent my current location from which I'm running this script.

Reproduce

Add the following two lines to ~/.bashrc

cd /<DEFAULT_DIR>/
alias lds='python -c "import os; print(os.getcwd())"'
alias ld='python /<ABS_DIR_LOCATION>/ld.py'

with ld.py:

import os;
print(os.getcwd())

Init bash and run:

> cd /<NOT-DEFAULT-DIR>/
> lds 
/<NOT-DEFAULT-DIR>/
> ld
/<DEFAULT_DIR>/
0

There are 0 answers