我正在争论我是否应该学习PowerShell,还是坚持使用Cygwin/Perl脚本/Unix shell脚本等等。

PowerShell的好处是,没有Cygwin的队友可以更容易地使用脚本;然而,我不知道我是否真的会写那么多通用脚本,或者人们是否会使用它们。

Unix脚本功能如此强大,PowerShell是否足以让我们切换到它呢?

以下是我在PowerShell中寻找的一些具体内容(或等效内容):

grep 排序 uniq Perl (PowerShell与Perl的能力有多接近?) AWK sed File(提供文件信息的命令) 等。


当前回答

在几行中,Cygwin和PowerShell是不同的工具,但是如果你安装了Cygwin,你可以在PowerShell会话中运行Cygwin可执行文件。我已经习惯了PowerShell,现在我不再使用grep, sort, awk等。在PowerShell中有很多内置的替代方案,如果没有,您可以在那里找到cmdlet。

我发现自己使用的主要工具是ssh.exe,但是在PowerShell会话中。

效果很好。

其他回答

我已经使用了一些PowerShell来实现脚本自动化。虽然环境看起来比Unix shell考虑得更周到,但实际上使用对象而不是文本流要笨拙得多,而且过去30年开发的许多Unix设施仍然缺失。

Cygwin仍然是我在Windows主机上选择的脚本环境。在完成任务方面,它肯定胜过其他选择。

在几行中,Cygwin和PowerShell是不同的工具,但是如果你安装了Cygwin,你可以在PowerShell会话中运行Cygwin可执行文件。我已经习惯了PowerShell,现在我不再使用grep, sort, awk等。在PowerShell中有很多内置的替代方案,如果没有,您可以在那里找到cmdlet。

我发现自己使用的主要工具是ssh.exe,但是在PowerShell会话中。

效果很好。

PowerShell中的cmdlet非常好,工作可靠。因为我是一名Java/ c#开发人员,所以它们的面向对象性非常吸引我,但这并不是一个完整的集合。由于它是面向对象的,因此它错过了POSIX工具集(例如awk和sed)的许多文本流成熟度。

The best answer I've found to the dilemma of loving OO techniques and loving the maturity in the POSIX tools is to use both! One great aspect of PowerShell is that it does an excellent job piping objects to standard streams. PowerShell by default uses an object pipeline to transport its objects around. These aren't the standard streams (standard out, standard error, and standard in). When PowerShell needs to pass output to a standard process that doesn't have an object pipeline, it first converts the objects to a text stream. Since it does this so well, PowerShell makes an excellent place to host POSIX tools!

最好的POSIX工具集是GnuWin32。它确实需要超过5秒钟的时间来安装,但这是值得的,据我所知,它不会修改你的系统(注册表,c:\windows\*文件夹等),除了将文件复制到你指定的目录。这是非常好的,因为如果您将工具放在共享目录中,许多人可以同时访问它们。

GnuWin32安装说明

下载并执行exe(它来自SourceForge网站)指向一个合适的目录(我将使用C:\bin)。它会在那里创建一个GetGnuWin32目录,你将在其中运行download.bat,然后是install.bat(不带参数),之后会有一个C:\bin\GetGnuWin32\gnuwin32\bin目录,这是Windows机器上曾经存在过的最有用的文件夹。将该目录添加到路径中,就可以开始了。

这里有很多很棒的答案,这是我的看法。PowerShell是准备好了,如果你是…例子:

grep = "Select-String -Pattern"

sort = " sort - object "

uniq = "Get-Unique"

file = "Get-Item"

cat = "Get-Content"

Perl/AWK/Sed不是命令,而是实用程序,因此很难比较,但在PowerShell中几乎可以做所有事情。

PowerShell功能非常强大,比Unix shell的标准内置功能更强大(但这只是因为它包含了许多通常分配给子程序的功能)。另外,考虑到你可以用任何。net语言编写小程序,包括IronPython、IronRuby、PerlNet等。或者你可以简单地从PowerShell调用你的Cygwin命令,忽略所有额外的功能,它将类似于Bash, KornShell,或任何…