Friday, March 9, 2018

What is the difference between braces{} and parenthesis() in Windows Power Shell?

In Windows Power Shell,
  • Braces{} enclose code and are not immediately evaluated. They must be called using the & operator (called the call operator)
  • Parenthesis() enclose code that is immediately called.

Example parenthesis:
$a=(5+5+25) and it evaluates immediately to 35
as seen here:



 Example braces:
On the other hand when you use braces, it is not evaluated.













What is inside the braces is code and how do you evaluate the code?

What you have inside the braces is called a ScriptBlock.
To run ScriptBlock code  you need to use the call operator & as in the next image.














It is easy.

No comments: