6

I have installed cygwin on Windows 11. Now, when I open the Windows command line, I want the bash.exe command to run the cygwin's bash command instead of bash linked with wsl (Windows subsystem for Linux). In other words, when I run bash.exe I don't want to see the "Windows Subsystem for Linux has no installed distributions." message, but instead run bash from my cygwin installation. I have tried adding the cygwin's "bin" directory to the Windows PATH environment variable, but with no effect.

Edit

Originally, I wrote that adding the cygwin's "bin" folder path to the Windows PATH environment variable had no effect, and while it is true for running bash-exe from the Windows cmd shell, it has meanwhile actually solved the problem of running bash.exe from the Python script, which in reality was my problem. I thought that running the command behaved equally no matter whether run from the cmd shell or Python script, but obviously there is a difference.

Adam
  • 171

2 Answers2

3

When you say "command line", I'm going to assume you mean the CMD shell, although you could potentially mean PowerShell.

For CMD, the easiest way to do this is probably with a doskey alias for bash:

doskey bash=D:\cygwin\bin\bash.exe $*

To make this permanent, see this answer.

For PowerShell, use the New-Alias equivalent and set it in your PowerShell profile.


Other options:

Windows Terminal

However, you may want to consider two other tools to make this even (IMHO) easier:

Both of these are Microsoft products and installable from the Microsoft Store.

You can set up a Cygin profile in Windows Terminal named "Bash", and using PowerToys run, activate it via _Bash. The prefix for any Terminal profile is _, but you can even skip that if you use it often. Power Run will sort it to the top based on usage.

I recommend turning on the option Open profiles in a new tab in PowerToys Run's "Windows Terminal" settings.

Adjust path

You could adjust your path, but you'll need to do that in the current CMD or PowerShell session, so you'd still need a startup CMD script or PowerShell profile. Given that, I think the Alias approach is probably better.

NotTheDr01ds
  • 28,025
0

I have the same issue as author, have WSL and Cygwin installed.

I set PATH: Win+Pause - Advanced System Settings - Environment Variables - PATH in both User and System sections have C:\Cygwin64\bin on the first place. Computer was rebooted.

I run Win+R - cmd.exe

SET PATH

I see c:\Cygwin64\bin on the first place.

where bash

c:\cygwin64\bin\bash.exe C:\Windows\System32\bash.exe

bash - bash is started

$ uname

CYGWIN_NT-10.0-19045

$ cat /etc/release

cat: '/etc/release': No such file or directory

BUT. Win-R - bash

$uname

Linux

$cat /etc/release

DISTRIB_ID=Ubuntu DISTRIB_RELEASE=22.04 DISTRIB_CODENAME=jammy DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS" ...

If I try to create Shortcut on Desktop:

Context menu - New - Shortcut - Type the location of item - type "bash" - Next - Finish

then shortcut created with Target: C:\Windows\System32\bash.exe