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

前端 未结 2 1002
囚心锁ツ
囚心锁ツ 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:37

    This is not trying to be a better answer. Just another way to say it.

    The variable expansion between apostrophes and quotes are the same as on UNIX shells (sh, ksh, bash). Using apostrophes will take the character string as-is, without processing any escapes.

    PS C:\Users\lit> $x = "`t"
    PS C:\Users\lit> $x
    
    PS C:\Users\lit> Write-Output "now${x}is"
    now     is
    PS C:\Users\lit> $x = '`t'
    PS C:\Users\lit> $x
    `t
    PS C:\Users\lit> Write-Output "now${x}is"
    now`tis
    PS C:\Users\lit> $word = "easy"
    PS C:\Users\lit> "PowerShell is $word"
    PowerShell is easy
    PS C:\Users\lit> 'PowerShell is $word'
    PowerShell is $word
    

提交回复
热议问题