What's the difference between single quote and double quote to define a string in powershell

前端 未结 2 1008
囚心锁ツ
囚心锁ツ 2020-12-05 17:45

Simple questions that\'s been bugging me: In powershell, I can define strings like so:

$s1 = \"Boogety boo\"

or

$s2 = \'.n         


        
2条回答
  •  难免孤独
    2020-12-05 18:30

    Double quotes allow variable expansion while single quotes do not:

    PS C:\Users\Administrator> $mycolor="red"
    PS C:\Users\Administrator> write-output -inputobject 'My favorite color is $mycolor'
    My favorite color is $mycolor
    

    Source: http://www.techotopia.com/index.php/Windows_PowerShell_1.0_String_Quoting_and_Escape_Sequences

    (I know version 1.0 but the principle is still the same)

提交回复
热议问题