0

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>/
ysig
  • 447
  • 4
  • 18
  • cant find my .bashrc ? Are you sure it exist ? – pippo1980 Sep 21 '22 at 17:38
  • @pippo1980 Are you using `bash` as your interactive shell? If you don't have a `.bashrc`, it will use `/etc/bashrc` – Barmar Sep 21 '22 at 17:38
  • This only happens when you use aliases? – Barmar Sep 21 '22 at 17:39
  • mmh dont have that too, I use cmd.exe to get the term – pippo1980 Sep 21 '22 at 17:40
  • @pippo1980 `bash` is the shell on Unix, not Windows. – Barmar Sep 21 '22 at 17:41
  • I tried to reproduce this on MacOS, I got `//` in both cases. – Barmar Sep 21 '22 at 17:42
  • Cannot reproduce. I have the same dir in both cases. – KamilCuk Sep 21 '22 at 17:43
  • I also can't reproduce it now - it should have been a server bug on the server I'm working on, but I don't know why. I leave it here in case someone has this bug / discovers what can lead to such a problematic behavior in the future :) (thank you for your answers - a hint may be that my home dir had no space left - but I have no clue whether this can actually play a role :/) – ysig Sep 23 '22 at 13:40

0 Answers0