Launchers
You shouldnot 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:
msys2_shell.cmd, the improved multi-purpose batch file from thefilesystem package. Runmsys2_shell.cmd --help for usage.
msys2.exe,mingw64.exe,mingw32.exe, the new pinnable launchers from themsys2-launcher package from @Elieux.GitHub,discussion,discussion
A nice explanation how toset up ConEmu to run MSYS2 inside it by jstine.
Configuration foran MSYS2 shell in Visual Studio Code.
msys2_env.bat from @DavidEGrayson.Gist,discussion
msys2.cmd,mingw64.cmd,mingw32.cmd from @Elieux.Gist
smart_msys from @jhasse.GitHub,discussion
MSYS2 here,MINGW64 here andMINGW32 here Explorer context menu items from @Elieux.Gist
msystem.bat and cmd/clink integration in thefilesystem-cmd package from @userzimmermann.PR,commits
git-bash.exe andstart-ssh-agent.cmd as part of the Git for Windows project from @dscho.GitHub,GitHub
Open MSYS2 here from @magthe, with contributions from @sushovan-dw and @ryanpfeeley.Gist+discussion
msys2_shell.bat,mingw64_shell.bat andmingw32_shell.bat, the old-school batch files fromold versions of thefilesystem package.
The idea
If you need to start a shell correctly, but none of the ways above suit you, devise your own way based on this knowledge:
- set
MSYSTEM=...into the environment, with the value of eitherMSYS,MINGW32, orMINGW64 - then run alogin shell
The typical one-liner if your options are limited isC:\\msys64\\usr\\bin\\env MSYSTEM=MSYS /usr/bin/bash -li.
Caveats:
- MSYS2 inherits multi-user capabilities from Cygwin and there is a notion of user's default shell. Not everyone's default shell isbash. 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.