3

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.

4
  • I have tried adding the cygwin's "bin" directory to the Windows PATH environment variable, but with no effect but where did you put it? At the beginning? At the end? The order of the paths is important
    – phuclv
    Jul 23, 2022 at 2:30
  • I've put it in the beginning. It has no effect on cmd shell, but the Python script which runs the bash.exe command now runs cygwin without an issue.
    – Adam
    Jul 24, 2022 at 13:18
  • I have tried adding the cygwin's "bin" directory to the Windows PATH : This was basically a good idea, but did you actulally verify afterwards from the command line, that the PATH is correct? In a Batch command line, you do this by simply typing path without any argument. Don't know about Powershell (but perhaps echo %PATH% should do). Jul 25, 2022 at 7:32
  • Just ensure the directory with Cygwin's bash.exe comes earlier in the PATH than the one with other bash implementation! But this is nothing specific to bash: It applies whenever you have on your hard disks different executable with the same name. Jan 24 at 13:38

2 Answers 2

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.

1
  • Thanks. Actuallly, the 'bash.exe' command was used in some Python script which I cannot modify, not in cmd. However, looks like adding the path to the cygwin's bin folder to PATH in Windows solved the problem.
    – Adam
    Jul 23, 2022 at 9:22
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

1
  • I realise that when application run via Win+R -> Run dialog, explorer.exe (parent of future bash.exe) has working directory pointing to %system_root%\system32. And as far as Windows OS first use current path to search for applications, it find wsl bash.exe there and execute it, desplite lower precedence of system32 directory in PATH env variable.
    – Evgeny L
    Feb 2 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .