相关疑难解决方法(0)

PowerShell在双引号内插值时输出数组项

我在PowerShell周围的数组和双引号中发现了一些奇怪的行为.如果我在数组中创建并打印第一个元素,例如:

$test = @('testing')
echo $test[0]

Output:
testing
Run Code Online (Sandbox Code Playgroud)

一切正常.但如果我在它周围加上双引号:

echo "$test[0]"

Output:
testing[0]
Run Code Online (Sandbox Code Playgroud)

仅评估了$ test变量,并且数组标记[0]被字面上视为字符串.简单的解决方法是避免在双引号中插入数组变量,或者首先将它们分配给另一个变量.但是这种行为是设计的吗?

powershell string-interpolation

13
推荐指数
3
解决办法
1万
查看次数

标签 统计

powershell ×1

string-interpolation ×1