如何在 Windows 上使用类似 Linux 的 Shell (bash) 进行开发?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12293494/
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 14:15:58  来源:igfitidea点击:

How to develop in Linux-Like Shell (bash) on Windows?

windowslinuxbash

提问by Sai Ye Yan Naing Aye

I'm Windows user. But according to my project requirements, I need to write Linux Shell Script(Bash shell). How to develop Linux Shell on Windows?

我是 Windows 用户。但是根据我的项目需求,我需要编写Linux Shell Script(Bash shell)。如何在 Windows 上开发 Linux Shell?

Is there any IDE for writing Linux Shell Scripting? Please share me some ideas and resource links.

是否有用于编写 Linux Shell 脚本的 IDE?请与我分享一些想法和资源链接。

采纳答案by Jayan

You have quite a number of options:

你有很多选择:

cygwin

赛格温

Install cygwin. It will give you a bash.

安装cygwin。它会给你一个bash。

mingw

明威

The minimal GNU for windows. Comes with set of commands, compilers. This came with my Git on Windows and now the default shell for small scripts

适用于 Windows最小 GNU。带有一组命令,编译器。这是我在 Windows 上的 Git 附带的,现在是小脚本的默认 shell

VM, such as VirtualBox

虚拟机,例如 VirtualBox

There are tons on VMs, VirtualBox being easy to use(it powers the Boot2Docker). You can do development and test on real Linux distros.

虚拟机上有很多,VirtualBox 易于使用(它为Boot2Docker 提供动力)。您可以在真正的 Linux 发行版上进行开发和测试。

Ubuntu on Windows 10

Windows 10 上的 Ubuntu

There is new kid on the block. This allows you to run User Space Ubuntu using Windows Subsystem for Linux (WSL). see more on it at Microsoft blog

街区上有新来的孩子。这允许您使用适用于 Linux 的 Windows 子系统 (WSL) 运行用户空间 Ubuntu。在Microsoft 博客上查看更多信息

Other notes/IDE support

其他说明/IDE 支持

Shell scripts should be small, requires less IDE etc. I use VIM with syntax highligthing. But it seems ShellEDmay be useful in your case. I got the link from answer for this question - Bash script plugin for Eclipse?

Shell 脚本应该很小,需要较少的 IDE 等。我使用带有语法高亮的 VIM。但似乎ShellED可能对您有用。我从这个问题的答案中得到了链接 - Eclipse 的 Bash 脚本插件?

IntelliJ has couple of pluginstoo for Bash..

IntelliJ 也有一些用于 Bash的插件

回答by Guillaume le Floch

There is cygwin , that's a linux console for windows.. so you can execute all the linux command with it.

有 cygwin ,这是一个用于 Windows 的 linux 控制台..所以你可以用它执行所有的 linux 命令。

回答by Basile Starynkevitch

Since you need to write linux shell scripts, you are learning Linux. So you should install Linux on your machine (preferably on its own partition and boot from it, otherwise in a VM).

既然你需要写linux shell脚本,那你就是在学习Linux。所以你应该在你的机器上安装 Linux(最好在它自己的分区上并从它引导,否则在 VM 中)。

Using cygwinor whatever imitation of Linux shell is not using Linux. You'll learn a lot more by installing and using Linux (and by developing on it with an editor like emacsor geditor gvim....). Also, take advantage that Linux is almost entirely free software, so you can study its source code and improve it.

使用cygwin或任何对 Linux shell 的模仿都不是使用 Linux。通过安装和使用 Linux(以及使用类似emacsgeditgvim...之类的编辑器在其上进行开发),您将学到更多。此外,利用 Linux 几乎完全是免费软件的优势,您可以研究其源代码并对其进行改进。

Not installing Linux is not doing yourself a favor.

不安装 Linux 对自己没有好处。

I believe cygwinis for those who love Linux but have to use Windows. It cannot give you the entire Linux feeling (e.g. you won't be able to write shell scripts looking into /procwhich does not exist in Windows, even with cygwin).

我相信cygwin是为那些喜欢 Linux 但必须使用 Windows 的人准备的。它不能给你整个 Linux 的感觉(例如/proc,即使使用 cygwin,你也无法编写查看Windows 中不存在的shell 脚本)。

回答by Einz

Install Cygwin to execute the commands. However you can use NotePad++ as editor which has native windows binaries.

安装 Cygwin 以执行命令。但是,您可以使用 NotePad++ 作为具有本机 Windows 二进制文件的编辑器。

http://www.cygwin.com/

http://www.cygwin.com/

http://notepad-plus-plus.org/

http://notepad-plus-plus.org/

回答by Paulo Scardine

I prefer Gow(Gnu on Windows) over Cygwin. Both will give you bash on Windows, but Cygwin has unnatural conventions for filesystem access (/cygdive/c/some/pathinstead of c:\some\path).

与 Cygwin 相比,我更喜欢Gow(Windows 上的 Gnu)。两者都会在 Windows 上为您提供 bash,但 Cygwin 有不自然的文件系统访问约定(/cygdive/c/some/path而不是c:\some\path)。

The native windows command terminal is pretty lame, take a look at Conemu.

本机 Windows 命令终端非常蹩脚,看看Conemu

I'm not aware of any bash IDE, but there are a plethora of windows text editors with decent syntax highlight for bash scripts. I like Notepad++and Sublime text(the multiple cursor feature from Sublime rocks!). I don't recommend bash for anything with more than 30 lines, if you ever feel the need for an IDE, perhaps the task is more suited for Python, Ruby or Perl (IMHO Python is more maintainable).

我不知道有任何 bash IDE,但是有大量的 Windows 文本编辑器具有良好的 bash 脚本语法高亮显示。我喜欢Notepad++Sublime 文本(来自 Sublime 的多光标功能!)。对于超过 30 行的任何内容,我不建议使用 bash,如果您觉得需要 IDE,也许该任务更适合 Python、Ruby 或 Perl(恕我直言,Python 更易于维护)。

回答by lmedinas

If you want to use a simple environment emulating all Linux environment as alternative to cygwin (more lightweight) you can try mingwand you can use notepad++ or emacs or vim to provide some syntax highlight on sh scripts.

如果您想使用模拟所有 Linux 环境的简单环境来替代 cygwin(更轻量级),您可以尝试mingw,您可以使用 notepad++ 或 emacs 或 vim 在 sh 脚本上提供一些语法高亮显示。

回答by user3694063

I had a similar problem. I like both Linux and Windows, and I am working on both systems, but for programming (and generally, for text editing) I use Windows, for different reasons. For example, I write C/C++ code on Windows, using the Windows DevC++ IDE, then I can compile this project on Linux, by sharing the files on LAN. Now I have to write long scripts, and I would like to do it in a similar way. Ok, maybe its a special request, but maybe I am not the only one who works in such a mixed environment. First, I tried notepad++ (it is suggested by others as well), but does it support syntax highlight for Linux scripts? I didn't found this feature... Then I tried gedit compiled for Windows. It requires the GTK library installed (actually it was already on my Windows). Gedit has syntax highlight for scripts! So I suggest using gedit for Windows for this case. The edited script can not directly be started/tested with it, but for editing, it is fine!

我有一个类似的问题。我喜欢 Linux 和 Windows,我在这两个系统上工作,但出于不同的原因,我使用 Windows 进行编程(通常用于文本编辑)。例如,我在 Windows 上编写 C/C++ 代码,使用 Windows DevC++ IDE,然后我可以在 Linux 上编译这个项目,通过在局域网上共享文件。现在我必须写长脚本,我想用类似的方式来做。好吧,也许这是一个特殊的要求,但也许我不是唯一在这种混合环境中工作的人。首先,我尝试了 notepad++(其他人也建议这样做),但它是否支持 Linux 脚本的语法高亮显示?我没有发现这个功能......然后我尝试了为Windows编译的gedit。它需要安装 GTK 库(实际上它已经在我的 Windows 上)。Gedit 有脚本的语法高亮!所以我建议在这种情况下使用 gedit for Windows。编辑后的脚本不能直接用它启动/测试,但用于编辑,没问题!

回答by Ivor

For Eclipse Luna Should use this one old version fails on UI error

对于 Eclipse Luna 应该使用这个旧版本因 UI 错误而失败

Help > Install New Software… > Add… 

Name: ShellEd

名称:壳牌

Location: http://sourceforge.net/projects/shelled/files/shelled/update/

位置:http: //sourceforge.net/projects/shelled/files/shelled/update/

回答by mdave16

Everyone has said to go full Linux or use various mocks. Cloud9.io is a good option if you don't need that much. You can set up a "workspace" which can be accessed online, lets you write in literally any language similar to np++, but the best part is, it's an online Linux, so you have a terminal, with all your shell commands - no mock up, no dual boot.

每个人都说要使用完整的 Linux 或使用各​​种模拟。如果您不需要那么多,Cloud9.io 是一个不错的选择。您可以设置一个可以在线访问的“工作区”,让您可以使用类似于 np++ 的任何语言编写,但最好的部分是,它是一个在线 Linux,因此您有一个终端,其中包含所有 shell 命令 - 没有模拟up,没有双启动。

The downside to this is that the free users aren't given that much power, so if you wanted to execute some high-level maths or output a large image, it will crash as you will be using too much memory. But it is still really worth getting into, it's only ever crashed once on me, and I do some pretty memory-intensive things.

这样做的缺点是免费用户没有那么大的权力,所以如果你想执行一些高级数学或输出大图像,它会因为你使用太多内存而崩溃。但它仍然非常值得进入,它只在我身上崩溃过一次,而且我做了一些非常占用内存的事情。

回答by Vineet Choudhary

The Bash shell is coming to Windows 10 in the upcoming Anniversary Update (Redstone).

Bash shell 将在即将到来的周年更新 (Redstone) 中进入 Windows 10。

The Bash shell is coming to Windows. Yes, the real Bash is coming to Windows, said Microsoft's Kevin Gallo at Build 2016 keynote. This is not a VM [Virtual Machine]. This is not cross-compiled tools. This is native."

Bash shell 即将登陆 Windows。是的,真正的 Bash 即将登陆 Windows,微软的 Kevin Gallo 在 Build 2016 主题演讲中说。这不是 VM [虚拟机]。这不是交叉编译工具。这是土生土长的。”

Here's the steps to run Bash on Windows 10 OS:

以下是在 Windows 10 操作系统上运行 Bash 的步骤:

  1. Open the Windows Start menu
  2. Type "bash" [hit enter]
  3. Which opens a console running Ubuntu's /bin/bashwith full access to all of Ubuntu user space
  1. 打开 Windows 开始菜单
  2. 输入“bash”[按回车键]
  3. 这将打开一个运行 Ubuntu 的控制台/bin/bash,可以完全访问所有 Ubuntu 用户空间

Yes, you are right, that means apt, set, ssh, rsync, find, ls, grep, awk, sed, sort, xargs, md5sum, gpg, curl, wget, apache, mysql, python, perl, ruby, ruby gem, php, gcc, tar, vim, emacs, diff, patch, nano...and most of the tens of thousands binary packages available in the Ubuntu archives!

是的,你是对的,这意味着aptsetsshrsyncfindlsgrepawksedsortxargsmd5sumgpgcurlwgetapachemysqlpythonperlrubyruby gemphpgcctarvimemacsdiffpatch...而且大部分,纳米数万的二进制包在 Ubuntu 档案中!

Reference

参考

  1. Step-vise Guide to Enable Windows 10's Ubuntu Bash Shell (Windows Subsystem for Linux)

  2. The Bash shell is coming to Windows 10 in the upcoming Anniversary Update (Redstone).

  3. Run native Bash on Ubuntu on Windows

  1. 启用 Windows 10 的 Ubuntu Bash Shell(适用于 Linux 的 Windows 子系统)的逐步指南

  2. Bash shell 将在即将到来的周年更新 (Redstone) 中进入 Windows 10。

  3. 在 Windows 上的 Ubuntu 上运行本机 Bash