Consider this bit of PowerShell:
PS> $x = 'y'
PS> ($x = 'y')
y
Why does adding the parens cause the value to get printed?
EDIT: Some more interesting cases:
PS> $z = ($x = 'y')
PS> $z
y
PS> $( $x = $y )
PS> $z = $( $x = $y )
PS> $z
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
parentheses tell the shell to evaluate the value within the parentheses first then print the result. in your first command, it’s assignment; However, the second is a command that will be evaluated and print the result, namely ‘y’
update
“PowerShell in Action” states difference between the subexpression construct and simple parentheses is how voidable statements are treated. ++,–,+=,-= operations are treated as voidable statement either.
In simple parentheses (), voidable statements is not discarded, but in subexpression $(), they are discarded.