Mayank
Mayank

Reputation: 113

Shell script equivalent in windows

I need to convert some .sh shell scripts to a Windows native script that can run in Windows environment without use of any external software like cygwin, migwin etc.

I know for Windows 10 there is Windows Subsystem for Linux (WSL), but it's in beta and also to use it we need to enable developer mode.

Some of the options that I have is converting them to batch files or Powershell scripts, but then I need to find each equivalent CMD/PS command and it will take really long time.

Is there any shortcut for running shell scripts on Windows?

Upvotes: 0

Views: 3435

Answers (2)

muratiakos
muratiakos

Reputation: 1092

I recommend to use Windows Subsystem for Linux, since it is already generally available and no longer in beta.

You can install it via PowerShell:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Once it is installed you can execute scripts interactively or pass in via bash, eg:

bash.exe myscript.sh

More info: https://learn.microsoft.com/en-us/windows/wsl/install-win10

Upvotes: 0

Jeff Zeitlin
Jeff Zeitlin

Reputation: 10799

Your only choices are:

  1. WSL, as you've noted - but it's no longer in beta.

  2. Install something like CygWin.

  3. Translate your *ix shell scripts into batch, PowerShell, VBScript, or JScript. You'll probably have better luck in terms of finding equivalents if you use PowerShell. Yes, it will take some time and study to do this, but the cost of any sort of script translation is going to be a learning curve; even if there were an automated tool for it, the results would be badly suboptimal. PowerShell adopts a significantly different model from other shells as pertains to the pipeline; if you try to write to the conventional model rather than using PowerShell as intended, you will find your frustration levels going through the roof.

By the strictest definition, your only choice for "Windows native script" is option 3 above; the others are not "Windows native script"; they're implementations of non-Windows tools that allow you to run *ix shell scripts (generally bash, rather than sh, csh, zsh, etc.) against Windows resources.

Upvotes: 2

Related Questions