header image

Variable squeezing

Posted by: | July 4, 2018 Comments Off on Variable squeezing |

When you’re developing code interactively how often do you set a variable and then display it to test the result? You can do that in one go using variable squeezing.

Normally you’d do:

PS> $test = 1
PS> $test
1

 

Set the variable and display the contents as two separate actions.

By enclosing the first statement in parentheses you accomplish both tasks

PS> ($test2 = 2)
2

 

Great for interactive work but you don’t want it in scripts as you’d be getting output every time you set a variable value!

under: PowerShell

Comments are closed.

Categories