

Is & ldquo; Dollar-sign & rdquo; Optional in powershell & ldquo; $ (...
source link: https://www.codesd.com/item/is-dollar-sign-optional-in-powershell.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Is & ldquo; Dollar-sign & rdquo; Optional in powershell & ldquo; $ () & Rdquo;
I've seen an example for setting the timestamps (creationtime, lastaccesstime, lastwritetime) of a file with powershell:
PS>$(get-item test.txt).lastwritetime=$(get-date "01/01/2020")
which seems to work.
This page: http://ss64.com/ps/syntax-operators.html about powershell operators says that "$( )"
is a "SubExpression operator".
But it also seems to work without the "$"
like:
PS>(get-item test.txt).lastwritetime=(get-date "01/01/2020")
and most powershell examples I've seen omit the "$"
when using parenthesis.
So, is the "Dollar-sign" optional in powershell "$()"
? Or is there some difference with/without the "$"
that I'm just not seeing.
Is "$()"
and "()"
actually 2 different operators that just happen to both be valid uses in the examples I have shown?
You need the $ sign to denote a sub expression if you use multiple statements or the statement is embedded in a string. Parenthesis without the $ is just a 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
Recommend
-
17
Magento: & ldquo; Image does not exist & rdquo; advertisements I'm importing a CSV file in Magento (version 1.9). I receive...
-
12
& ldquo; azure & rdquo; not recognized in Azece powershell advertisements For the first time I'm trying out Azure Powershell. I'm sele...
-
10
can not find the class of symbols & ldquo; Builder & rdquo; advertisements I have recently downloaded Android Studio, I t...
-
5
Javascript & ldquo; Private & rdquo; Vs properties of the instance advertisements I'm doing some Javascript R&D and,...
-
10
C # & ldquo; Undefined method & rdquo; When adding a new method to a simulated interface advertisements I am curren...
-
4
Labeling & ldquo; to-do & rdquo; s and colorful text in Markdown advertisements I'm using the GitHub flavoured Mark...
-
21
Imap_search () unknown search criteria & ldquo; OR & rdquo; advertisements Trying to build a IMAP Search query to filter...
-
13
Is a & ldquo; for & rdquo; Is the loop necessary if the elements of the vector numpy depend on the previous element? advertisements
-
7
Unexpected result of & ldquo; F \ t \ b \ bg \ n & rdquo; In Visual C ++ advertisements I wrote a one line program in Vi...
-
4
Disable & ldquo; Save image & rdquo; In the iOS Web application advertisements I want to disable the "s...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK