You should not launch sh.exe directly as that doesn't start a login shell or set the correct environment variables for the type of shell that you want to use. Instead, your best choices are:
A nice explanation how to set up ConEmu to run MSYS2 inside it by jstine.
msys2.cmd, mingw64.cmd, mingw32.cmd from @Elieux. Gist
MSYS2 here, MINGW64 here and MINGW32 here Explorer context menu items from @Elieux. Gist
Open MSYS2 here from @magthe, with contributions from @sushovan-dw and @ryanpfeeley. Gist+discussion
If you need to start a shell correctly, but none of the ways above suit you, devise your own way based on this knowledge:
MSYSTEM=...into the environment, with the value of either
- then run a login shell
The typical one-liner if your options are limited is
C:\\msys64\\usr\\bin\\env MSYSTEM=MSYS /usr/bin/bash -li.
- MSYS2 inherits multi-user capabilities from Cygwin and there is a notion of user's default shell. Not everyone's default shell is bash. To correctly figure out the default shell from outside (i.e. without directly calling the POSIX APIs), you can use this shell one-liner or an equivalent:
getent passwd $(whoami) | cut -d: -f7
- There are other environment variables that control MSYS2 at runtime or initialization. See the source of launchers above to figure them out if needed.
- You might need to set
CHERE_INVOKING=1for the shell to stay in the current working directory.
- If you need to run a specific command instead of an interactive shell, you still need to go through a login shell, e.g.
... /usr/bin/bash -lc python.