Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop Powershell insisting on one dash in parameters?

Tags:

powershell

It seems that somebody has subtly changed the way that parameter switches are parsed on powershell. On some machines "split-path c:\x\y --parent" works. On some it fails. Can anyone tell me a) what causes the difference and b) how can I stop it?

like image 624
Julian Birch Avatar asked Jun 09 '10 20:06

Julian Birch


1 Answers

Switch parameters should work in the same way in both V1 and V2 (that means -parent is the right syntax).

In your case --parent should be bound to an parameter as a string. It should not be interpreted as a switch. You can test the binding via Trace-Command

Trace-Command parameterbinding -Expression { split-path c:\x\y --parent} -PSHost

Further info:

Considering --: every string behind -- is interpreted as argument, no matter if it looks like a switch.

[14]: function test { 
    param([switch]$sw, [string]$str) 
    write-host switch is $sw
    write-host str is $str 
}
[15]: test 1
switch is False
str is 1
[16]: test -sw
switch is True
str is
[17]: test -- -sw
switch is False
str is -sw
like image 160
stej Avatar answered Sep 28 '22 08:09

stej