Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to run Bash scripts on Windows? [closed]

Tags:

bash

windows

I have bought and I use Windows 7 Ultimate, and I like to use it to develop applications. One of the down sides (as with every OS) is that I can not run Bash scripts. Is there a way to run Bash scripts on Windows by installing some software? It is ok if it does not work 100%, but as long as the most common functionality is available it should be great.

like image 440
Tower Avatar asked Jun 20 '11 15:06

Tower


People also ask

Can you run Bash scripts on Windows?

Yes, now with Bash Shell in Windows 11 and Windows 10, you can now create and run Bash shell scripts and incorporate Bash commands into a Windows batch file or PowerShell script.

How do I run a .sh file in Windows without Bash?

Install the GitBash tool in the Windows OS. Set the below Path in the environment variables of System for the Git installation. Type 'sh' in cmd window to redirect into Bourne shell and run your commands in terminal.

Can I run .sh file on Windows?

SH file is very similar to the batch file of the Windows operating system and can be run in the Linux-based operating system. It is also possible to run . SH file in Windows 10 using Windows Subsystem for Linux.


3 Answers

Install Cygwin, which includes Bash among many other GNU and Unix utilities (without whom its unlikely that bash will be very useful anyway).

Another option is MinGW's MSYS which includes bash and a smaller set of the more important utilities such as awk (you may also want to check the competing fork - Mingw-w64). Personally I would have preferred Cygwin because it includes such heavy lifting tools as Perl and Python which I find I cannot live without, while MSYS skimps on these and assumes you are going to install them yourself.

Updated: If anyone is interested in this answer and is running MS-Windows 10, please note that MS-Windows 10 has a "Windows Subsystem For Linux" feature which - once enabled - allows you to install a user-mode image of Ubuntu and then run Bash on that. This provides 100% compatibility with Ubuntu for debugging and running Bash scripts, but this setup is completely standalone from Windows and you cannot use Bash scripts to interact with Windows features (such as processes and APIs) except for limited access to files through the DrvFS feature.

like image 69
Guss Avatar answered Oct 20 '22 18:10

Guss


Best Option I could find is Git Windows Just install it and then right click on and click "Git Bash Here" this will open a bash windowenter image description here

This will open a bash window like this: enter image description here

and the linux commands work...

I've tried 'sh' , 'vi' , 'ssh' , 'curl' ,etc... commands

like image 54
Garvit Jain Avatar answered Oct 20 '22 18:10

Garvit Jain


If you're looking for something a little more native, you can use getGnuWin32 to install all of the Unix command line tools that have been ported. That plus winBash gives you most of a working Unix environment. Add console2 for a better terminal emulator and you almost can't tell you're on Windows!

Cygwin is a better toolkit overall, but I have found myself running into surprise problems because of the divide between it and Windows. None of these solutions are as good as a native Linux system though.

You may want to look into using virtualbox to create a linux VM with your distro of choice. Set it up to share a folder with the host os, and you can use a true linux development environment, and share with windows. Just watch out for those EOL markers, they get ya every time.

like image 30
Spencer Rathbun Avatar answered Oct 20 '22 19:10

Spencer Rathbun