powershell - Why does a function that calls another with the same parameter name clobber its own parameter with that name? -
consider following code:
function f2 { [cmdletbinding()] param( $e4da2f9 ) process{} } function f1 { [cmdletbinding()] param ( $e4da2f9 ) process { $e4da2f9 $command = 'f2' $splat = @{ e4da2f9 = 'value passed f2' } # following line clobbers function's $e4da2f9... . $command @splat | out-null # ...but line not # f2 @splat | out-null $e4da2f9 } } f1 'value passed f1' running it, surprisingly yields following:
value passed f1 value passed f2 if comment out . $command ... , uncomment f2 @splat ... yields expected result:
value passed f1 value passed f1 - why happen?
- is there fundamental difference between calling function plainly , calling using
. $functionname? - how call function recursively using if have name in variable?
it's because dot-sourced function rather running (&). said run f2 in scope of f1.
replacing offending line this:
& $command @splat | out-null makes work want.
Comments
Post a Comment