在powershell中定义字符串的单引号和双引号有什么区别 [英] What's the difference between single quote and double quote to define a string in powershell
本文介绍了在powershell中定义字符串的单引号和双引号有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一直困扰着我的简单问题:在 powershell 中,我可以像这样定义字符串:
Simple questions that's been bugging me: In powershell, I can define strings like so:
$s1 = "Boogety boo"
或
$s2 = '.net rocks'
解释器有区别吗?
推荐答案
双引号允许变量扩展而单引号不允许:
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
来源:http://www.techotopia.com/index.php/Windows_PowerShell_1.0_String_Quoting_and_Escape_Sequences
(我知道1.0版本但原理还是一样)
(I know version 1.0 but the principle is still the same)
这篇关于在powershell中定义字符串的单引号和双引号有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文