PowerShell – Single Quote vs. Double Quote

What’s the difference with quotes?

Single quote: It is taken literally and provided back.
Double quotes: PowerShell looks for the $ character inside of the double quotes. Once found, it assumes the following characters are the name of a variable up to the first space, is a variable name.

Sample:

[System.String]$a = 'Hello'
$b = '$a World!'
# $b prints: $a World!
$c = "$a World!"
# $c prints: Hello World!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s