Skip navigation

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

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."
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish