Running .bat files in Cygwin (bash or zsh) works when calling directly.

However, if I'm located at a different folder and I call the .bat file by relying on PATH variable, it will say command not found.

If I have a .bat file in environment PATH, how can I make Cygwin to execute it from any directory? This works for .exe files but apparently not for .bat files.

  • Your question is a bit unclear. I guess with bat file , you mean a Windows CMD Batch file, right? But what do you mean by "calling directly"? Perhaps you could show a small example batch file, and how you "call it directly". Dec 29, 2022 at 9:52

2 Answers 2


It sounds like you need to be more specific. It does work for BAT files and EXE files. What may be happening is that you are coincidentally using a name that is already taken by something earlier in your path.

If you have PATH=C:\1;C:\2;C:\3

And you make a C:\3\foo.BAT

But there is already a C:\1\foo.EXE

Then when you type "foo", it will hit c:\1\foo.exe before finding c:\3\foo.bat.

This has plagued me from time to time.

I find the "which" command helpful in these situations.

  • PATH delimiter is ; not ,
    – Hannu
    Aug 19, 2015 at 18:53
  • Good catch. I was thinking verbally but writing as if it was code. Bad habit! :)
    – ClioCJS
    Aug 20, 2015 at 18:38

Cygwin is able to execute .exe and .bat files based on Cygwin's executable attribute or magic cookies (MZ for .exe and :\n for .bat) in a file.

Take note at attribute x:

# printf '@echo OK' >bad.bat
# printf ':\n@echo OK' >good.bat
# ls -l *.bat
-rw-r--r--  bad.bat
-rwxr-xr-x  good.bat

Now good.bat is executable (according to Cygwin) and even completed via TAB in Bash.

If your mount point supports acl you can mark any file as executable:

chmod a+x my.bat

You must log in to answer this question.

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