I am using:
I have an environment variable looking like an absolute path (/path/to/dir
) but I'm using it to construct a git URL. At some point, it's getting translated to C:/Program Files/Git/path/to/dir
. It seems like Python is at fault:
In a git bash shell:
$ export VAR=/path/to/dir
$ echo $VAR
/path/to/dir
$ python
>>> import os
>>> os.environ['VAR']
'C:/Program Files/Git/path/to/dir'
git bash is not translating the path, but Python is?
In a Windows Command Prompt, Python gets it right:
C:\>set VAR=/path/to/dir
C:\>echo %VAR%
/path/to/dir
C:\>python
>>> import os
>>> os.environ['VAR']
'/path/to/dir'
Can anyone explain what's going on here? And how can I prevent the translation in a bash shell?
EDIT: I should add that my python script runs on OS X and Windows, so if anyone does have a solution it would be good if worked on both platforms.
My guess would be that this is not python at fault, but the git bash shell.
Maybe the git bash shell is lying to you when you look at the variable.
Or, try to not put the first / and add it again later (if translation does not occurs).
If I try with cygwin, it works:
$ export test="/bin"
$ python
>>> import os
>>> os.environ["test"]
'/bin'