-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
Cmdlets such as Get-ChildItem / Get-Item bind the first positional argument to the -Path parameter.
This is convenient on the one hand, because -Path supports wildcard expressions, so that you can use commands such as Get-ChildItem *.txt
Passing paths meant to be literal paths that way typically works, given that * and ? aren't permissible characters in actual file names; however, [ and ] are, and passing literal paths with such characters causes them to be interpreted as wildcards too, potentially resulting in non-matches (e.g., Get-Item tmp[0].txt won't match a file literally named tmp[0].txt) and even errors.
While escaping wildcard characters is possible, it is tricky and cumbersome, which is the primary reason that the -LiteralPath parameter was introduced.
Given how common it is to pass literal paths, it would be convenient to be able to shorten:
Get-Item -LiteralPath tmp[0].txtto:
Get-Item -lp tmp[0].txt # wishful thinkingNote that while using elastic syntax does work - -l is currently enough to uniquely identify -LiteralPath with Get-Item for instance - it is not future-proof (and should never be used in scripts), whereas having an immutable, official parameter-name alias is.
Granted, in scripts it's preferable to use the verbose, original names of parameter names (and to prefer named arguments over positional ones and to never rely on elastic syntax), but given how common it is to pass literal paths, -lp is still a desirable convenience, both on the command line and in scripts.
Environment data
Written as of:
PowerShell Core v6.0.2