1

Hy everybody, could someone explain to me why this happens?

$Script = {"My name is $($ARGS[0]) and my surname is $($ARGS[1])"} 



& $SCRIPT "CARL","WHITE" 

Output expected: MY name is CARL and my surname is WHITE

Actual output: My name is CARL WHITE and my surname is

that's because $args[0] is an array itself, this means that I should change the script like this:

$Script = {"My name is $($ARGS[0][0]) and my surname is $($ARGS[0][1])"} 
1

1 Answer 1

3

It happens because you only provide 1 argument - an array consisting of the two string literals CARL and WHITE.

Remove the , and PowerShell will bind the two strings as two separate arguments instead:

& $Script "CARL" "WHITE" 
Sign up to request clarification or add additional context in comments.

1 Comment

thanks! I should have tried days long to understand this by my own!

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.