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

后端 未结 3 1062
长发绾君心
长发绾君心 2020-12-15 04:01

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

if ($true -eq $true){}

but not



        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 04:51

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

提交回复
热议问题