Skip to main content
Dave Mason - Mastodon Dave Mason - LinkedIn Dave Mason - GitHub Dave Mason - Counter Social

PowerShell Equality Comparison Operators

Dave Mason - PowerShell Equality Comparison Operators

When comparing two values in a programming or scripting language, you are most likely going to use syntax consisting of characters you learned as a youngster in math. Those who are new to programming will almost certainly recognize them. Python, Java, C, C++, Javascript, C#, and R all use those same characters and syntax. They're on a list of the top programming languages of 2021 along with a few others. The comparison operators and their syntax are as follows:


Comparison Syntax
Equals ==
Not Equals !=
Greater Than >
Greater Than or Equal >=
Less Than <
Less Than or Equal <=

Against The Norm

When comparing two values in PowerShell, you'll have to march to the beat of a different drum. The syntax is drastically different:

Comparison Syntax
Equals -eq
Not Equals -ne
Greater Than -gt
Greater Than or Equal -ge
Less Than -lt
Less Than or Equal -le

I've quipped that people should stop creating programming languages out of spite. In the same vein, I can't help but wonder what the creators of PowerShell were thinking when they chose the syntax for equality comparison. Why, PowerShell? Why?

Comments

Post comment