Curtis Johnstone

January 27, 2011

Microsoft PowerShell Single Quote vs Double Quote

Always having to remind myself of this when I write powershell scripts:

  • Single quotes return a literal string consisting of whatever is enclosed between them – there is no evaluation.
  • Double quotes evaluates the string; it will expand and variables that you have enclosed.

Example:

$month = ‘May’

Write-Host “The current month is $month”

> Output = The current month is May

Single quotes return a literal string consistening of whatever is enclosed between them – there is no evaluation.
Double quotes evaluates the string; it will expand and variables that you have enclosed.
E.g.
$month = ‘May’
Write-Host “The current month is $month”
Output = May
PowerShell Line Continuation with the Backtick
The Backtick’ character (`), tells the PowerShell parser to continue the command on the next line.
GOTCHA:  You need one space character BEFORE it, and no extra characters after it, for it to work.
Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks

2 Comments »

  1. Correction, output will be:
    The current month is May

    Comment by Box293 — August 14, 2012 @ 8:02 pm

  2. Thanks for the correction – my laziness got the best of me.

    Curtis

    Comment by Curtis Johnstone — August 14, 2012 @ 8:19 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress