powershell奇怪的输出数组索引

时间:2017-03-09 03:11:40

标签: powershell

我有一个数组(大于示例)

$ccheck = ("44729375","74729375")

for ( $i = 0; $i -lt $ccheck.Count; $i++ ) {
     cd $env:userprofile\desktop\CURL\
     $ccheck[$i]
     $curlexec ="curl -L ""https://server.net/$ccheck[$i]""";
     $curlexec
}
带有for循环的

我在迭代数组。当询问带$ccheck[$i]的索引时,我得到的第一个索引是44729375。但是从$curlexec变量我得到整个数组,我只想要i索引。

所以我从变量https://server.net/44729375 74729375获得输出$curlexec。我不知道什么是错的。

1 个答案:

答案 0 :(得分:3)

阅读Get-Help 'about_Quoting_Rules'

使用子表达式语法

 $curlexec ="curl -L ""https://server.net/$($ccheck[$i])""";
 ##### note the change                    $(           )

辅助变量

 $ccheckaux = $ccheck[$i]
 $curlexec ="curl -L ""https://server.net/$ccheckaux""";