I'm a Mac user and new to Windows. How can I execute a shell script in Windows?
Generally, I would save the text file with the extension
.sh and run it via Terminal. But how could I do that in Windows?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Scripts with a
.sh suffix are generally Bourne shell scripts (or bash, or ksh, or zsh -- all shells derived from the Bourne shell). (Note that on Unix-like systems, including MacOS, the
.sh suffix isn't necessary; the OS looks at the
#!/bin/sh line at the top of the script to determine how to execute it.)
Windows doesn't provide a Bourne-like shell.
You can install Cygwin, which provides a Unix-like environment under Windows -- but it doesn't have a particularly "native" environment. (Editorial comment: Cygwin is great for people like me who need to use Windows but would really rather be using Unix.)
Or, instead of trying to write and run Unix-like shell scripts, you can write Windows batch files. These generally have a
.cmd suffix. They use the same commands and syntax as the Windows interactive command prompt.
There's also the relatively new Windows PowerShell; I'm not familiar with it myself, but I've heard good things about it.
You can use Cygwin. It provides linux like environment in windows.
UWIN is a computer software package created by David Korn which allows programs written for the operating system Unix be built and run on Microsoft Windows with few, if any, changes. Some of the software development was subcontracted to Wipro, India.
Check this UWIN - Unix for Windows
Salient features of UWIN
Uses of UWIN
Drawbacks of UWIN
That software was used to teach us Linux Command when i was in college.. really good one..
Cygwin is a Unix-like environment and command-line interface for Microsoft Windows.
Good about is that Cygwin provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment.
Interix is a component of the Services for Unix (SFU) release 3.0 and 3.5 (this last one is distributed freely).
The most recent releases of Interix, 5.2 and 6.0, are components of the Windows Server 2003 R2, Windows Vista Enterprise and Ultimate editions and Windows Server 2008 under the name SUA (Subsystem for Unix-based Applications) Version 6.1 is included in Windows 7 (Enterprise and Ultimate) and Windows Server 2008 R2 (all editions)
There is another way to do this with the Anniversary update for Windows 10. There is now a Bash (Ubuntu) shell available in Windows.
In order to use it you need to install the feature since it is not enabled by default.
Control Panel ->
Turn Windows Features On and Off.
Select the checkbox for
Windows Subsystem for Linux (Beta). This will install the feature and prompt for a reboot.
Then you can open a command prompt via run ->
cmd then type
bash or run ->
This will give you a bash shell with no virtual machine or Cygwin or virtualbox.
Although the existing answers here were correct at the time, Windows 10 does now optionally include a modified version of Ubuntu running a full bash shell.
Once installed, you can open a bash prompt (much like you would a terminal in OS X/macOS) and run the script as usual, ie:
chmod +x myscript.sh ./myscript.sh
If you want to run a script directly from Windows you could create a shortcut in the same directory and set the 'Target' to something like:
C:\Windows\System32\bash.exe -c "./myscript.sh"
If the path of your script is relative to the location of the shortcut (like the example above) ensure the 'Start in' field is also blank.
The right answer was given in a comment by Kenaniah, you have to use batch files. You need to name your shell code file to *.bat, then you can run it by clicking it or simply type its name in the terminal. Notice that the windows terminal does not work exactly like the unix terminal. You will find much help and tutorials for the commands and syntax all over the web. There is also a possibility to use the Windows PowerShell, which seems to be more unix-like.