I have a function 'foo' and a variable '$foo' referencing it.
function foo
{
param($value)
$value + 5
}
$foo = foo
$foo
I can call $foo without args, but how can I pass parameters? This does not work:
$foo 5
$foo(5)
Actually the goal is to write such code:
function bar {
param($callback)
$callback 5
}
bar(foo)
The problem is when you do
$foo = foo
You put the result of the function in the variable $foo, not the function itself !
Try this :
$foo = get-content Function:\foo
And call it like this
& $foo 5
Hope it helps !
Use a script block.
# f.ps1
$foo =
{
param($value)
$value + 5
}
function bar
{
param($callback)
& $callback 5
}
bar($foo)
Running it:
> ./f.ps1
10
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With