arrays - Why does $A+$B and $A,$B interact differently with Test-Path -
i have 2 arrays $a
, $b
both potentially empty.
$a = $b = @()
this works:
$a+$b | test-path
this not work:
$a,$b | test-path
and returns error:
test-path : cannot bind argument parameter 'path' because empty array.
i have expected both expressions fail, +
operator adding 1 empty array another, meaning resulting array still empty?
looking @ overall types of both methods shows same type.
ps y:\> $e = $a+$b ps y:\> $e.gettype() ispublic isserial name basetype -------- -------- ---- -------- true true object[] system.array ps y:\> $f = $a,$b ps y:\> $f.gettype() ispublic isserial name basetype -------- -------- ---- -------- true true object[] system.array
so why $a+$b
& $a,$b
interact differently test-path
?
$a+$b | ...
concatenates $a
, $b
before passing resulting array pipeline. pipeline unrolls (still empty) array, $null
, test-path
never called.
$a,$b | ...
constructs array 2 nested arrays before passing pipeline. pipeline unrolls outer array , feeds each element (the empty arrays $a
, $b
) test-path
, causing error observed.
basically you're doing $a+$b → @()
in former, , $a,$b → @(@(), @())
in latter case.
Comments
Post a Comment