What To Do / Not to Do in PowerShell: Part 7

Do you know the difference between 'quotes' and "quotes?"

Don Jones

June 22, 2011

1 Min Read
ITPro Today logo in a gray background | ITPro Today

Windows PowerShell is pretty flexible. For example, you can use either a forward / slash or a back slash as a path separator. It also lets you use 'single' or "double" quotation marks for strings (I recently saw someone refer to them as 'speech marks,' which I thought was neat).

But do you know the difference?

Inside "double quotes" only, PowerShell will do two special things:

  • Look for the backtick ` escape character, and escape whatever follows it. This lets you, for example, use `t as a tab character.

  • Look for the dollar sign, and assume that whatever $follows to the next white space is a variable name, and then replace it with the variable's contents. So "$this" or "${this is also legal}" would be replaced. PowerShell just calls the standard ToString() method on the variable, so complex objects will usually just return their type name.

None of this happens inside 'single' quotes. As a best practice, the PowerShell community generally agrees that you should use 'singles' for strings unless you explicitly need the special features offered by "doubles."

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like