如何在Windows上开发类linux Shell (bash) ?

时间:2022-09-23 00:14:39

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脚本(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吗?请分享一些想法和资源链接给我。

10 个解决方案

#1


20  

You have quite a number of options:

你有很多选择:

cygwin

cygwin

Install cygwin. It will give you a bash.

安装cygwin。它会给你一个重击。

mingw

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

VM,比如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.

vm上有大量的虚拟机,很容易使用(它为Boot2Docker提供支持)。您可以在真正的Linux发行版上进行开发和测试。

Ubuntu on Windows 10

Ubuntu在Windows上10

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 (WSL)的Windows子系统运行用户空间Ubuntu。更多信息请访问微软博客

Other notes/IDE support

其他notes / IDE支持

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

Shell脚本应该很小,需要更少的IDE等等。但是看来带壳可能对你有用。我得到了这个问题的答案链接——Eclipse的Bash脚本插件?

IntelliJ has couple of plugins too for Bash..

IntelliJ也有几个用于Bash的插件。

#2


10  

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/path instead of c:\some\path).

我喜欢高(Gnu on Windows)胜过Cygwin。两者都将使您对Windows产生冲击,但是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++和卓越的文本(来自卓越岩石的多重游标功能!)我不推荐使用超过30行代码的bash,如果您曾经觉得需要一个IDE,那么也许这个任务更适合Python、Ruby或Perl (IMHO Python更易于维护)。

#3


8  

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。是的,真正的冲击是Windows,微软的Kevin Gallo在Build 2016大会上说。这不是VM[虚拟机]。这不是交叉编译工具。这是本地。”

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

  1. Open the Windows Start menu
  2. 打开Windows开始菜单
  3. Type "bash" [hit enter]
  4. 输入“bash”(回车)
  5. Which opens a console running Ubuntu's /bin/bash with full access to all of Ubuntu user space
  6. 它打开一个运行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!

是的,你是对的,这意味着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…在Ubuntu档案中有成千上万的二进制包!

如何在Windows上开发类linux Shell (bash) ?

如何在Windows上开发类linux Shell (bash) ?

Reference

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

    Step-vise指南支持Windows 10的Ubuntu Bash Shell (Linux的Windows子系统)

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

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

  3. Run native Bash on Ubuntu on Windows

    在Windows上运行在Ubuntu上的本地Bash。

#4


5  

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 cygwin or 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 emacs or gedit or 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(与一个编辑器,通过开发像emacs或中或gvim ....)。另外,利用Linux几乎完全是免费软件的优势,您可以研究它的源代码并对其进行改进。

Not installing Linux is not doing yourself a favor.

不安装Linux对你没有好处。

I believe cygwin is 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 /proc which does not exist in Windows, even with cygwin).

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

#5


2  

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

有cygwin,这是windows的linux控制台。因此您可以使用它执行所有的linux命令。

#6


1  

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/

#7


1  

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

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

#8


1  

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/

#9


1  

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命令——没有模拟,没有双引导。

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.

这样做的缺点是免费用户没有得到那么大的权力,所以如果您想执行一些高级数学或输出一个大的图像,它将崩溃,因为您将使用太多的内存。但它仍然值得一试,它只在我身上发生过一次,我做了一些非常需要记忆的事情。

#10


-1  

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,然后通过在LAN上共享文件,在Linux上编译这个项目。现在我必须写长脚本,我想用类似的方式写。好吧,也许这是一个特殊的要求,但也许我不是唯一一个在这样复杂的环境中工作的人。首先,我尝试过notepad++(其他人也建议使用),但是它支持Linux脚本的语法高亮显示吗?我没有发现这个功能…然后我尝试为Windows编译gedit。它需要安装GTK库(实际上它已经在我的Windows上)。Gedit有语法高亮显示脚本!所以我建议在这种情况下使用gedit作为Windows。编辑后的脚本不能直接用它启动/测试,但是对于编辑来说,它是可以的!

#1


20  

You have quite a number of options:

你有很多选择:

cygwin

cygwin

Install cygwin. It will give you a bash.

安装cygwin。它会给你一个重击。

mingw

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

VM,比如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.

vm上有大量的虚拟机,很容易使用(它为Boot2Docker提供支持)。您可以在真正的Linux发行版上进行开发和测试。

Ubuntu on Windows 10

Ubuntu在Windows上10

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 (WSL)的Windows子系统运行用户空间Ubuntu。更多信息请访问微软博客

Other notes/IDE support

其他notes / IDE支持

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

Shell脚本应该很小,需要更少的IDE等等。但是看来带壳可能对你有用。我得到了这个问题的答案链接——Eclipse的Bash脚本插件?

IntelliJ has couple of plugins too for Bash..

IntelliJ也有几个用于Bash的插件。

#2


10  

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/path instead of c:\some\path).

我喜欢高(Gnu on Windows)胜过Cygwin。两者都将使您对Windows产生冲击,但是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++和卓越的文本(来自卓越岩石的多重游标功能!)我不推荐使用超过30行代码的bash,如果您曾经觉得需要一个IDE,那么也许这个任务更适合Python、Ruby或Perl (IMHO Python更易于维护)。

#3


8  

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。是的,真正的冲击是Windows,微软的Kevin Gallo在Build 2016大会上说。这不是VM[虚拟机]。这不是交叉编译工具。这是本地。”

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

  1. Open the Windows Start menu
  2. 打开Windows开始菜单
  3. Type "bash" [hit enter]
  4. 输入“bash”(回车)
  5. Which opens a console running Ubuntu's /bin/bash with full access to all of Ubuntu user space
  6. 它打开一个运行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!

是的,你是对的,这意味着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…在Ubuntu档案中有成千上万的二进制包!

如何在Windows上开发类linux Shell (bash) ?

如何在Windows上开发类linux Shell (bash) ?

Reference

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

    Step-vise指南支持Windows 10的Ubuntu Bash Shell (Linux的Windows子系统)

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

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

  3. Run native Bash on Ubuntu on Windows

    在Windows上运行在Ubuntu上的本地Bash。

#4


5  

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 cygwin or 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 emacs or gedit or 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(与一个编辑器,通过开发像emacs或中或gvim ....)。另外,利用Linux几乎完全是免费软件的优势,您可以研究它的源代码并对其进行改进。

Not installing Linux is not doing yourself a favor.

不安装Linux对你没有好处。

I believe cygwin is 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 /proc which does not exist in Windows, even with cygwin).

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

#5


2  

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

有cygwin,这是windows的linux控制台。因此您可以使用它执行所有的linux命令。

#6


1  

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/

#7


1  

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

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

#8


1  

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/

#9


1  

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命令——没有模拟,没有双引导。

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.

这样做的缺点是免费用户没有得到那么大的权力,所以如果您想执行一些高级数学或输出一个大的图像,它将崩溃,因为您将使用太多的内存。但它仍然值得一试,它只在我身上发生过一次,我做了一些非常需要记忆的事情。

#10


-1  

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,然后通过在LAN上共享文件,在Linux上编译这个项目。现在我必须写长脚本,我想用类似的方式写。好吧,也许这是一个特殊的要求,但也许我不是唯一一个在这样复杂的环境中工作的人。首先,我尝试过notepad++(其他人也建议使用),但是它支持Linux脚本的语法高亮显示吗?我没有发现这个功能…然后我尝试为Windows编译gedit。它需要安装GTK库(实际上它已经在我的Windows上)。Gedit有语法高亮显示脚本!所以我建议在这种情况下使用gedit作为Windows。编辑后的脚本不能直接用它启动/测试,但是对于编辑来说,它是可以的!