$($variableName) 在 PowerShell 中的可扩展字符串中是什么意思? [英] What does $($variableName) mean in expandable strings in PowerShell?

查看:23
本文介绍了$($variableName) 在 PowerShell 中的可扩展字符串中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上看到了许多使用它的示例脚本.最近,我在 自动化 TFS:

I've seen a number of example scripts online that use this. Most recently, I saw it in a script on automating TFS:

[string] $fields = "Title=$($taskTitle);Description=$($taskTitle);Assigned To=$($assignee);"
$fields += "Area Path=$($areaPath);Iteration Path=$($iterationPath);Discipline=$($taskDisciplineArray[$i]);Priority=$($i+1);"
$fields += "Estimate=$($taskEstimateArray[$i]);Remaining Work=$($taskRemainingArray[$i]);Completed Work=$($tasktaskCompletedArray[$i])"

据我所知,$($taskTitle) 似乎等同于 $taskTitle.我错过了什么吗?是否有任何理由使用括号和额外的美元符号?

From what I can tell, $($taskTitle) seems to be equivalent to $taskTitle. Am I missing something? Is there any reason to use the parentheses and extra dollar sign?

推荐答案

语法有助于评估其中的表达式.

The syntax helps with evaluating the expression inside it.

$arr = @(1,2,3)

$msg1 = "$arr.length"
echo $msg1 # prints 1 2 3.length - .length was treated as part of the string

$msg2 = "$($arr.length)"
echo $msg2 # prints 3

您可以在 http://ss64.com/ps/syntax-operators.html 阅读更多信息

这篇关于$($variableName) 在 PowerShell 中的可扩展字符串中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆