Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling a bash script into a windows executable

I have a script which was origionally made for Linux, but adapted to run with Cygwin in windows, and if you already have the executables (sh, cp, mv, etc.) then you can run it without Cygwin. The only problem is that the script also uses a few hundred (yes hundreds) of other executables. Is there any way I can compile this script into a regular executable and pack these other supporting files in as resources?

The script is ~1600 lines long which is probably too long to confortably re-implement by hand in C++. I am looking to compile the script into something which windows can execute without having to make edits to the path to include a bunch of third party executables. A way to contain all this.

like image 338
Daisetsu Avatar asked Aug 11 '11 22:08

Daisetsu


People also ask

Can a Bash script be run on Windows?

Note that bash runs natively on Windows 10, which is different from using emulators like 'cygwin' for Windows which enabled GNU tools to run on unsupported Windows environment. Also, Linux subsystem for Windows 10 is only available on the 64-bit version of the OS.

Can Bash script be compiled?

If we want to obfuscate what the script is doing we can compile it to binary using shc . As this is often not installed, we can add it using brew on mac or apt-get for Debian based Linux systems.

How do I run a .sh file in Windows?

Execute Shell Script FilesOpen Command Prompt and navigate to the folder where the script file is available. Type Bash script-filename.sh and hit the enter key. It will execute the script, and depending on the file, you should see an output.


4 Answers

I doubt that the solution you have in mind is feasible.

Instead, I'd modify the script so that the first thing it does is figure out where all those hundreds of executables are. Then either set $PATH appropriately, or invoke each one by its full pathname.

Or you can have an installer that installs the executables in a specified or user-chosen location, then re-generates the script (from an input file) so it knows where the executables are. Ship with the-script.in, then have the installer perform textual substitutions to generate the-script from the-script.in.

like image 172
Keith Thompson Avatar answered Sep 28 '22 18:09

Keith Thompson


I point out:

RPM and SHC

as a possible solution for your problem. Maybe this tools helps you to do the job.

like image 35
H_7 Avatar answered Sep 28 '22 19:09

H_7


Using SHC to Cygwin is possible to compile bash to exe Ok. Realy old, but I was looking for it and decide to do my self and make it public. http://goo.gl/M1NSY

like image 45
Erico Schuch Avatar answered Sep 28 '22 17:09

Erico Schuch


Use ports of the required utils and use some application virtualization tool to package it all up. Cameyo is a free one. Forget Cygwin, that thing is huuuge :)

like image 33
Camilo Martin Avatar answered Sep 28 '22 17:09

Camilo Martin