locked
Difference between single quotes ' ' and double-quotes " " RRS feed

  • Question

  • Hi,

    I see peoples using  ' ' and others using " ", what are the différences between those quotes?

    Thanks,

    François

    Monday, December 1, 2014 11:05 AM

Answers

  • Powershell will evaluate simple variables inside double quotes.

    Powershell will NOT evaluate anything inside single quotes.

    Example:


    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________ Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx


    • Edited by Sam Boutros Monday, December 1, 2014 11:26 AM
    • Marked as answer by FRacine Monday, December 1, 2014 12:43 PM
    Monday, December 1, 2014 11:24 AM
  • Look up "powershell expandanbale string" for a formal explanation.

    http://blogs.msdn.com/b/powershell/archive/2006/07/15/variable-expansion-in-strings-and-herestrings.aspx


    ¯\_(ツ)_/¯

    • Marked as answer by FRacine Monday, December 1, 2014 12:43 PM
    Monday, December 1, 2014 11:37 AM

All replies

  • Powershell will evaluate simple variables inside double quotes.

    Powershell will NOT evaluate anything inside single quotes.

    Example:


    Sam Boutros, Senior Consultant, Software Logic, KOP, PA http://superwidgets.wordpress.com (Please take a moment to Vote as Helpful and/or Mark as Answer, where applicable) _________________________________________________________________________________ Powershell: Learn it before it's an emergency http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx http://technet.microsoft.com/en-us/scriptcenter/dd793612.aspx


    • Edited by Sam Boutros Monday, December 1, 2014 11:26 AM
    • Marked as answer by FRacine Monday, December 1, 2014 12:43 PM
    Monday, December 1, 2014 11:24 AM
  • Look up "powershell expandanbale string" for a formal explanation.

    http://blogs.msdn.com/b/powershell/archive/2006/07/15/variable-expansion-in-strings-and-herestrings.aspx


    ¯\_(ツ)_/¯

    • Marked as answer by FRacine Monday, December 1, 2014 12:43 PM
    Monday, December 1, 2014 11:37 AM
  • 1) the only thing that gets changed from the exact text between singlequotes is that two consecutive singlequotes will be changed to a single singlequote

    2) as a style preference I always use singlequotes when no expansion is wanted.  That way, a doublequote
    warns to look for the presence of string expansion.  The only exception is a null string where I always use two double quotes because for me that is easier to read as two characters as opposed to two consecutive singlequotes 

    Monday, December 1, 2014 5:27 PM
  • Good advice.   THe single quotes is its own escape as is the double quote.

    PS C:\scripts> 'Hello ''dude'
    Hello 'dude
    PS C:\scripts> "Hello ""dude"""
    Hello "dude"
    PS C:\scripts>


    ¯\_(ツ)_/¯

    Monday, December 1, 2014 5:50 PM
  • Also, a here-string will not use the quote characters inside the string as escape characters.

    <#c:#> @'
    >> ''
    >> '@
    >>
    ''
    <#c:#> @"
    >> ""
    >> "@
    >>
    ""
    

    Monday, December 1, 2014 6:01 PM
  • Another good point Larry.

    The here string is independent. Once you are inside almost anything goes.


    ¯\_(ツ)_/¯

    Monday, December 1, 2014 6:03 PM