Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cygwin running script from one batch file?

I know when Cygwin installs there is a batch file that is used to launch it in Windows. But if I want to run a script without launching Cygwin and doing "./script"

How do I create a batch file to do that?

As in... just have one batch file that when clicked, opens Cygwin and runs the shell script.

like image 604
Aaron Avatar asked Nov 27 '11 04:11

Aaron


People also ask

How do I write a bash script in Cygwin?

So you have to use simply /bin/ as path for bash. Do a simple check: into a CygWin terminal type the command ls /bin/bash.exe : it list the executable for bash. open a windows CMD and type the command dir C:\cygwin\bin\bash.exe : it list the executable for bash.


2 Answers

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.

like image 187
Jakob Buron Avatar answered Sep 22 '22 14:09

Jakob Buron


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"
like image 35
Austin Hastings Avatar answered Sep 23 '22 14:09

Austin Hastings