0

I have an array of numbers (larger than the example)

$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
}

with a for loop I am iterating over an array. When asking for index with $ccheck[$i] I am getting the first index which is 44729375. But from $curlexec variable I am getting the whole array and I just want the i index.

So I am getting this as as output https://server.net/44729375 74729375 from the variable $curlexec. I don't know what's wrong.

1 Answer 1

3

Read Get-Help 'about_Quoting_Rules'.

Use either sub-expression syntax

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

or an auxiliary variable

 $ccheckaux = $ccheck[$i]
 $curlexec ="curl -L ""https://server.net/$ccheckaux""";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.