如何在windows环境下运行Linux shell脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10581506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:18:28  来源:igfitidea点击:

How to run Linux shell script on windows environment

linuxbashshellbatch-file

提问by KItis

I have housekeeping script which is running on Redhat operating system.

我有在 Redhat 操作系统上运行的内务管理脚本。

I have a requirement where i want to run the same script in the Windows environment.

我有一个要求,我想在 Windows 环境中运行相同的脚本。

So i have 3 options

所以我有3个选择

  1. Write a new script for windows
  2. Convert Linux script in to windows script using some tool.
  3. Use Cygwin and run the script without making any change to the linux script.
  1. 为 Windows 编写一个新脚本
  2. 使用一些工具将 Linux 脚本转换为 Windows 脚本。
  3. 使用 Cygwin 并运行脚本而不对 linux 脚本进行任何更改。

So i want to know what would be the best option to select.

所以我想知道什么是最好的选择。

Thanks in advance for any help

在此先感谢您的帮助

采纳答案by Attila

It depends on how complex the scripts are, whether you want to make changes to them and what utilities the existing ones use.

这取决于脚本的复杂程度、是否要对它们进行更改以及现有脚本使用哪些实用程序。

If the scripts are very complex, you will be better off keeping the original and use Cygwin.

如果脚本非常复杂,最好保留原始脚本并使用 Cygwin。

If you want to maintain the scripts and port changes back and forth, you will want to use the original (and use Cygwin)

如果您想来回维护脚本和端口更改,您将需要使用原始版本(并使用 Cygwin)

If the script uses some Unix utilities that have not been ported to Cygwin, you either need to do the porting yourself (to be able to keep the original scripts) or convert the scripts to use Windows equivalent (or similar) programs

如果脚本使用了一些尚未移植到 Cygwin 的 Unix 实用程序,则您需要自己进行移植(以便能够保留原始脚本)或将脚本转换为使用 Windows 等效(或类似)程序

So I'd recommend you using Cygwin in most cases, unless the scripts are very easy to translate to Windows batch format

所以我建议你在大多数情况下使用 Cygwin,除非脚本很容易转换为 Windows 批处理格式

回答by Andreas Wong

You can try colinux

你可以试试colinux

http://www.colinux.org/

http://www.colinux.org/

Cooperative Linux is the first working free and open source method for optimally running Linux on Microsoft Windows natively. More generally, Cooperative Linux (short-named coLinux) is a port of the Linux kernel that allows it to run cooperatively alongside another operating system on a single machine.

Cooperative Linux 是第一个在 Microsoft Windows 上以最佳方式运行 Linux 的免费开源方法。更一般地说,Cooperative Linux(简称 coLinux)是 Linux 内核的一个端口,允许它在一台机器上与另一个操作系统协同运行。

回答by c2h2

I would recommend option 3 and it is the only way to run the same script (assuming script = bash script) under windows.

我会推荐选项 3,它是在 Windows 下运行相同脚本(假设脚本 = bash 脚本)的唯一方法。

回答by Jason Morgan

4: Install a port of BASH for windows, e.g. win-bash
5: Use SUA/SFU, see this link

4:为windows安装一个BASH端口,例如win-bash
5:使用SUA/SFU,见这个链接

回答by BigMike

As stated in comment, I'd like to see or know what the script does. Under windows there are a couple of options for scripting now. (Powershell, vbscript, javascript, plain old batch files), but really it depends on what the original script does.

正如评论中所述,我想看看或知道脚本的作用。在 Windows 下,现在有几个用于编写脚本的选项。(Powershell、vbscript、javascript、普通的旧批处理文件),但实际上这取决于原始脚本的作用。

IMHO is just plain overkill installing the whole cygwin or a bash porting just for moving files or performing other trivial tasks.

恕我直言,安装整个 cygwin 或仅用于移动文件或执行其他琐碎任务的 bash 移植只是简单的矫枉过正。