The "=" sign is always an assignment and never an equivalence test, right?

This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Richard Siddaway Richard Siddaway 9 months ago.

  • Author
    Posts
  • #36297
    Profile photo of Kiran
    Kiran
    Participant

    To test a variable's value, you would always use "-eq" right? You would never use "=", right? I believe that "=" in PowerShell 4 is always an assignment operator.

  • #36300
    Profile photo of Bob McCoy
    Bob McCoy
    Participant

    In all versions of PowerShell that is the case. You can use "=" in an if statement and it doesn't generate an error. Instead it will do the assignment and the 'if' result will always be $true.

  • #36306
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    = has always been the assignment operator in PowerShell and
    -eq has always been the equality comparison operator

    for more information on operators see the following help files
    about_Arithmetic_Operators
    about_Assignment_Operators
    about_Comparison_Operators
    about_Logical_Operators
    about_Operators
    about_Type_Operators

You must be logged in to reply to this topic.