我正在争论我是否应该学习PowerShell,还是坚持使用Cygwin/Perl脚本/Unix shell脚本等等。
PowerShell的好处是,没有Cygwin的队友可以更容易地使用脚本;然而,我不知道我是否真的会写那么多通用脚本,或者人们是否会使用它们。
Unix脚本功能如此强大,PowerShell是否足以让我们切换到它呢?
以下是我在PowerShell中寻找的一些具体内容(或等效内容):
grep
排序
uniq
Perl (PowerShell与Perl的能力有多接近?)
AWK
sed
File(提供文件信息的命令)
等。
作为一个从1997年到2010年专注于Windows企业开发的人,显而易见的答案是PowerShell,因为前面给出的所有好的理由(例如,它是微软企业战略的一部分;与Windows/COM/.NET集成良好;使用对象而不是文件提供了一个“更丰富的”编码模型)。出于这个原因,我在过去两年左右的时间里一直在使用和推广PowerShell,并明确地相信我是在遵循“比尔之言”。
然而,作为一个实用主义者,我不再确定PowerShell是一个很好的答案。虽然这是一款出色的Windows工具,并且为填补Windows命令行这一历史性的漏洞提供了非常必要的一步,但我们都看到微软对消费者计算的控制正在下滑,微软似乎越来越有可能面临一场大规模的战斗,以保持其操作系统对未来企业的重要性。
事实上,鉴于我发现我的工作越来越多地处于不同的环境中,我发现目前使用Bash脚本要有用得多,因为它们不仅可以在Linux、Solaris和Mac OS X上工作,而且还可以在cygwin的帮助下在Windows上工作。
因此,如果您相信操作系统的未来是商品化的,而不是垄断的,那么选择一种灵活的开发工具策略,在可行的情况下远离专有工具似乎是有意义的。然而,如果你认为你的未来被所有的雷德蒙德所主宰,那么就选择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机器上曾经存在过的最有用的文件夹。将该目录添加到路径中,就可以开始了。
TL;DR——我不讨厌Windows或PowerShell。我在Windows或PowerShell上什么都做不了。
我个人仍然觉得PowerShell充其量只能说是平淡无奇。
tab completion of directory paths do not compound, requiring the user to enter a path separator after every name completion.
I still feel like Windows doesn't even have the concept of a path or of what a path is, with no accessible user home indicator ~/ short of some @environment://somejibberish/%user_home%
NTFS is still a mess and seemingly always will be. Good luck navigating.
cmd-esque interface, The dinosaur cmd.exe is still visible in PowerShell, Edit → Mark still being the only way to copy information, and copying only in the form of rectangular blocks of visible terminal space. and Edit → Mark still being the only way to paste strings into the terminal.
Painting it blue doesn't make it any more attractive. I don't mind Microsoft developers having a taste in color though.
Windows always opens at top left corner of screen. For somebody who uses vertical task bars this is incredibly annoying, especially considering that the Windows task bar will cover the only corner of the window that gives access to copy/paste functionality.
关于Windows包含的工具,我不能说太多。由于有一整套开源的、免费授权的CLI工具,而且PowerShell附带了这些工具,据我所知,没有一个是完全令人失望的。
PowerShell的wget的参数似乎与GNU的wget无法相比。谢谢,希望之光便携无用。
PowerShell POSIX与bash不兼容,特别是&&运算符没有被处理,使得最简单的条件命令也不能跟在后面。
我不了解人类;我试过了,真的;我仍然试着给它一个机会,希望下次我打开它的时候,它不会那么无用。我不能在PowerShell中做任何事情,我也几乎不能在真正的项目中将GNU工具引入Windows。
MySysGit为我提供了带有几个GNU工具的陈旧cmd.exe提示符,它仍然非常令人印象深刻,但最终路径补全工作了。Git命令将在Git Bash中运行。
Mintty for MySysGit为MySysGit的环境提供了Cygwin界面,使复制和粘贴一个东西(选择复制(鼠标),Shift+Ins粘贴,多么现代…)然而,像git push这样的东西在Mintty中被破坏了。
我并不是要抱怨,但我仍然看到Windows上命令行可用性的巨大问题,即使使用了Cygwin这样的工具。
注:仅仅因为在PowerShell中可以做一些事情,并不意味着它就可用。可用性比能力更重要,这也是我作为消费者在使用产品时所关注的问题。