PowerShell comparison operators

2019-03-05 06:46发布

问题:

PowerShell has a unique set of comparison operators: -eq -gt -lt -ne etc. I vaguely remember using such operators in a different language, but can't recollect which one.

Which other languages use such notations? what is reason for not using the standard operators (==, >,<, !=)?

回答1:

The Unix test command for instance uses similar operators. Perl has operators like that too, although without the leading hyphen.

The reason for PowerShell to use mnemnics rather than symbols for the comparison operators is probably that some of the commonly used comparison symbols are already in use for other operations (= → assignment, > → redirection).