Is "Dollar-sign" optional in powershell "$()"? -


i've seen example setting timestamps (creationtime, lastaccesstime, lastwritetime) of file powershell:

ps>$(get-item test.txt).lastwritetime=$(get-date "01/01/2020") 

which seems work.

this page: http://ss64.com/ps/syntax-operators.html powershell operators says "$( )" "subexpression operator".

but seems work without "$" like:

ps>(get-item test.txt).lastwritetime=(get-date "01/01/2020") 

and powershell examples i've seen omit "$" when using parenthesis.

so, "dollar-sign" optional in powershell "$()" ? or there difference with/without "$" i'm not seeing.

is "$()" , "()" 2 different operators happen both valid uses in examples have shown?

you need $ sign denote sub expression if use multiple statements or statement embedded in string. parenthesis without $ grouping operator.

$($x = 1; $y =2; $x + $y).tostring() //3  ($x = 1; $y =2; $x + $y).tostring() // invalid syntax  ($x = 1 + 2).tostring() //3  "$(1 +2)"  //3 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -