Skip to content

Instantly share code, notes, and snippets.

@ainformatico
Created November 8, 2011 12:05
Show Gist options
  • Save ainformatico/1347598 to your computer and use it in GitHub Desktop.
Save ainformatico/1347598 to your computer and use it in GitHub Desktop.
Executing Cygwin Bash scripts on Windows
:: Execute a bash script with the same filename, source: bit.ly/ef7iQw
@echo off
setlocal
if not exist "%~dpn0.sh" echo Script "%~dpn0.sh" not found & exit 2
set _CYGBIN=C:\cygwin\bin
if not exist "%_CYGBIN%" echo Couldn't find Cygwin at "%_CYGBIN%" & exit 3
:: Resolve ___.sh to /cygdrive based *nix path and store in %_CYGSCRIPT%
for /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%~dpn0.sh"') do set _CYGSCRIPT=%%A
:: Throw away temporary env vars and invoke script, passing any args that were passed to us
endlocal & %_CYGBIN%\bash --login "%_CYGSCRIPT%" %*
#!/bin/bash
echo "Hello world!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment