Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
大括号在PowerShell变量声明中有什么意义吗?_Powershell_Variables - Fatal编程技术网

大括号在PowerShell变量声明中有什么意义吗?

大括号在PowerShell变量声明中有什么意义吗?,powershell,variables,Powershell,Variables,我遇到过如下声明的变量(或参数): ${var_name} = "Hello world!" ${var_name hello } = "Hello world!2" $var_name = "Hello world!" 据我所知,这与以下情况没有什么不同: $var_name = "Hello world!" 我想知道第一个例子中的大括号是不是有什么意义。它们是否会改变变量的行为 PowerShell变量名称中的大括号允许在变量名称中使用任意字符。如果变量名中没有“病理”字符,

我遇到过如下声明的变量(或参数):

${var_name} = "Hello world!"
${var_name   hello   } = "Hello world!2"

$var_name = "Hello world!"
据我所知,这与以下情况没有什么不同:

$var_name = "Hello world!"

我想知道第一个例子中的大括号是不是有什么意义。它们是否会改变变量的行为

PowerShell变量名称中的大括号允许在变量名称中使用任意字符。如果变量名中没有“病理”字符,则不需要大括号,也没有效果


你会发现“生成”的代码有时会使用卷轴括号,因为它们保证变量名是有效的。

< P> <代码> {} /代码>括号用于在变量的中间或内部具有空格的声明变量,如:

${var_name} = "Hello world!"
${var_name   hello   } = "Hello world!2"

$var_name = "Hello world!"
这是不一样的,因为你不能用空格保存变量中的数据,powershell在空格之前理解变量,除非它在大括号内


祝你今天愉快。(:

乍一看可能不明显的是,您可以使用
${}
中的任何内容,例如:

${c:\tmp\foo.txt}="Hello World"       # C: uses file system provider

效果取决于提供程序,对于文件系统提供程序,示例更改指定文件的内容。

${f!a@n#c$y v%a^r&i*a(b)l-e n=a+m/e}
这有什么影响?