Sunday, February 4, 2018

Function calls passed to other functions might need parentheses

One user was trying to call a function and pass the resulting array of strings to another function, like so:

Func2 Func1

The idea was to call Func2 with the results of Func1 as the parameter. The problem here, though, is that PowerShell interprets Func1 as a string literal despite it not being quoted. (It's trying to be helpful.) The solution is to parenthesize the argument:

Func2 (Func1)

This actually calls Func1 and passes that to Func2.

No comments:

Post a Comment