为什么等于“-eq"?在 PowerShell 中,而不仅仅是“="? [英] Why is equals "-eq" in PowerShell and not just "="?

查看:63
本文介绍了为什么等于“-eq"?在 PowerShell 中,而不仅仅是“="?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

结构 -ne-eq-gt 看起来至少很奇怪.

The constructs -ne, -eq, and -gt looks at least strange.

if ($true -eq $true){}

但不是

if ($true = $true){}

解释是什么?

推荐答案

基本上答案是 Unix 一直这样做.果然,如果您编写了一些您将使用的 Bash 脚本,那么将您的 PowerShell 语法知识一对一地转移到 Bash 实际上非常好.

Basically the answer is that it is how Unix has done it forever. Sure enough, if you write some Bash scripts that's what you'll use and it's actually nice to have your PowerShell syntax knowledge transfer over one for one to Bash.

Bruce Payette 的Windows PowerShell in Action,第二版(Kindle 位置 3391)对此进行了详细回答.

It is answered in detail in Bruce Payette's Windows PowerShell in Action, Second Edition (Kindle Location 3391).

让我们谈谈最有争议的设计决策PowerShell 语言.

Let’s talk about the most contentious design decision in the PowerShell language.

获胜者是:为什么我们不使用传统的符号进行比较,例如 >、>=、<、<=、== 和 !=?

And the winner is: why the heck didn’t we use the conventional symbols for comparison like >, >=, <, <=, ==, and !=?

答案是 > 和 <字符用于输出重定向.因为PowerShell 是过去 30 年中的 shell 和所有 shell 语言已经使用 > 和 <对于 I/O 重定向,人们期望 PowerShell应该做同样的事情.在 PowerShell 的第一个公开测试版期间,这话题引发了持续数月的讨论.

The answer is that the > and < characters are used for output redirection. Because PowerShell is a shell and all shell languages in the last 30 years have used > and < for I/O redirection, people expected that PowerShell should do the same. During the first public beta of PowerShell, this topic generated discussions that went on for months.

我们看了一个各种替代方案,例如模态解析,有时 > 意味着大于有时它意味着重定向.我们看了运算符的替代字符序列,如 :> 或 ->,用于重定向或比较.我们进行了可用性测试并持有焦点小组,并最终确定了我们开始的内容.

We looked at a variety of alternatives, such as modal parsing where sometimes > meant greater-than and sometimes it meant redirection. We looked at alternative character sequences for the operators like :> or ->, either for redirection or comparison. We did usability tests and held focus groups, and in the end, settled on what we had started with.

重定向操作符是 > 和 <,比较操作符是取自 Unix test(1) 命令.我们期望,因为这些运营商拥有 30 年的血统,他们足以且适合于在 PowerShell 中使用.(我们也预计人们将继续抱怨这个决定,但希望不会再持续 30 年.)

The redirection operators are > and <, and the comparison operators are taken from the Unix test(1) command. We expect that, because these operators have a 30-year pedigree, they’re adequate and appropriate to use in PowerShell. (We also expect that people will continue to complain about this decision, though hopefully not for 30 more years.)

这篇关于为什么等于“-eq"?在 PowerShell 中,而不仅仅是“="?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆