Why is equals "-eq" in PowerShell and not just "="? Why is equals "-eq" in PowerShell and not just "="? powershell powershell

Why is equals "-eq" in PowerShell and not just "="?


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.

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

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 !=?

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.

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.)


Because > and < are stream redirection operators in most shells. Well, except that PowerShell doesn't support stream input redirection. That aside, it would be more difficult to parse/interpret > in some cases to be redirect stdout and in other cases greater than. Additionally by using the -<operator_name> approach you can have many more operators than there are intuitive symbols e.g. -contains, -notcontains, -is, -replace, -split, -match, etc. Execute man about_operators as a starting point to explorer all the operators supported by PowerShell.


The operator = is already the assignment operator. In order not to confuse the comparison and the assignment operator they choose for another operator. In this case for -eq because this is already in use in other (UNIX) scripting languages.