Search code examples
windowscygwin

Cygwin Bash.exe vs. mintty.exe


I am trying to run Unix commands on both the bash.exe and mintty.exe, found in Cygwin64/bin (e.g., usr/bin/bash.exe). When I try to run the Unix commmand ls, I get bash: ls: command not found. However, when I click on the desktop icon for the Cygwin terminal, and enter ls into the resulting Cygwin terminal, the Unix commmands like ls work! Why do Unix commands not work on bash.exe and mintty.exe, but on the terminal the results from clicking the icon? Furthermore, what is the difference the two shells brought by bash.exe and mintty.exe?


Solution

  • These two programs are not in any way alternatives to one another. Bash is a shell, and MinTTY is a terminal emulator. MinTTY normally runs your user's shell within itself, which may or may not be Bash. You normally use the two programs together.

    If you examine the MinTTY shortcut that Cygwin's setup.exe builds, you will find that it isn't a simple launch of the program. It runs it as mintty -, which tells MinTTY to run your user's shell as a "login" shell.

    This is the problem you have run into. If you run bash.exe without options, you just get the naked shell, with its default configuration, which means it doesn't do things like add the Cygwin /bin to your PATH. Likewise, if you run mintty.exe without options, it runs your user's shell without options. When you give a dash to mintty.exe instead of a program name, it runs your user's shell as a login shell: bash -l, rather than just bash. That option causes Bash to read in a bunch of startup scripts immediately after launch, which sets up the command PATH and a lot more besides.

    Thus, if you had to run bash.exe outside MinTTY for some reason, you could say bash -l to get behavior somewhat closer to that of bash.exe when run via mintty -. You would lose out on all of the terminal emulator features, however. MinTTY has much better copy-paste behavior than Windows' console does, for example, particularly on Windows 8 and older.

    (The initial release of Windows 10 included a much-improved console, and the more recent Windows Terminal add-on improves things further, but MinTTY remains the more powerful option, IMHO, particularly when working with Cygwin.)

    Say man mintty at a Cygwin command prompt for a fuller explanation of all the things MinTTY does for you. This particular question was answered in the INVOCATION section of the MinTTY manual page.