-1

I open "Git Bash" (git version 2.21.0.windows.1) and print the SHELL env variable, it displays bash.

$ echo $SHELL
bash

But doing the same with python (either version 2 or 3), results in:

>>> import os
>>> print(os.environ['SHELL'])
C:\Users\serj\bash

For some reason it prepends the current directory and the result is bogus, as there's no bash there. All other env variables are OK.

If this is a bug, how do I go about knowing if I should report to Python, git or MSYS ? Regular MSYS+python do work, so seems something special in this git package.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
Sergio Martins
  • 897
  • 2
  • 8
  • 18
  • `SHELL` is `/usr/bin/bash` here, same WinGit version. Are you starting Bash with "Git Bash" shortcut? Did you override this variable? – ivan_pozdeev May 11 '19 at 10:34
  • 1
    I suspect you may have some `.bash*` in `%USERPROFILE%` from Cygwin or something, or there's otherwise something funny in your system configuration (e.g. custom symlinks). – ivan_pozdeev May 11 '19 at 10:37
  • I'm starting bash with the desktop icon shortcut, yes. I didn't override the variable, and it displays fine with echo, it's just python that's acting funny – Sergio Martins May 11 '19 at 10:52
  • Read my post(s) carefully. Did you notice it has a full path for me? The lack of a full path (that you report) is not normal. – ivan_pozdeev May 11 '19 at 10:55
  • 1
    Understood now, I found an "export SHELL=bash" in an old .bash_profile. I wonder why the bash.exe from my standalone MSYS2 installation doesn't have this behaviour (doesn't prepend cwd), while "Git Bash" does it. Anyway, thanks, I can make progress now! – Sergio Martins May 11 '19 at 11:06
  • MSYS2 doesn't use `%USERPROFILE%` as its `$HOME` ([but can be configured so](https://stackoverflow.com/questions/33942924/how-to-change-home-directory-and-start-directory-on-msys2)), so a `.bash_profile` there won't affect it. – ivan_pozdeev May 11 '19 at 11:11

1 Answers1

1
$ echo $SHELL
bash

This is not normal. It should be /usr/bin/bash. Something must be wrong with your system configuration or the way you are starting Git Bash. E.g.:

  • The shortcut is wrong and starting it with incorrect environment. (For me, it points to "C:\Program Files\Git\git-bash.exe" --cd-to-home, and current directory is %HOMEDRIVE%%HOMEPATH%.)
  • You have some custom Bash startup scripts in %USERPROFILE% that override SHELL (e.g. you also have Cygwin and have pointed its $HOME to your %USERPROFILE%, too).
  • There are some custom configuration changes in Git's MinGW environment (e.g. in its /etc), or disk layout changes, e.g. custom symlinks, or environment variables are set at Windows level that alter MinGW's behavior.
ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152