Cygwin running script from one batch file? Cygwin running script from one batch file? bash bash

Cygwin running script from one batch file?


To run "foo.bsh", create a batch file with the following contents and run it:

    set PATH=C:\cygwin\bin;%PATH%    c:\cygwin\bin\bash.exe c:\path\to\foo.bsh

The "C:\cygwin\bin" part can differ depending on your chosen install location of cygwin.


You might try something like this to trampoline from CMD to BASH (or whatever sh-variant):

    : <<TRAMPOLINE    @echo off    bash -c "exit 0" || (echo.No bash found in PATH! & exit /b 1)    bash "%~f0" "%*"     goto :EOF     TRAMPOLINE    #####################    #!/bin/bash  -- it's traditional!    echo "Hello from $SHELL"


I'd like to expand on the answer given by Austin Hastings to allow it to work without Cygwin in the path and to work in the directory setup with the bat file (so even a shortcut with a different "Start in " path is used). The changes are to include full path to bash, use option -l to make bash setup properly with paths and environment and to pass the current directory to bash as the first argument which is popped of (using shift). Remember to use Unix newlines in the file or you will get lots of errors. Also use UTF8 instead of ANSI.

: <<TRAMPOLINE@echo offC:\cygwin\bin\bash -c "exit 0" || (echo.No bash found in PATH! & exit /b 1)setlocal EnableDelayedExpansionfor %%i in (%*) do set _args= !_args! "%%~i"C:\cygwin\bin\bash -l "%~f0" "%CD%" %_args%goto :EOF TRAMPOLINE######################!/bin/bash  -- it's traditional!cd "$1"shiftecho Working from $PWD

Edit: Fixed the trampoline code to pass arguments properly to bash. BAT files do not have a bash equivalent of "$@" and a loop processing each argument is made and then passed to bash.exe. Now properly handles arguments with spaces.