Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Introduce -lp as an alias for -LiteralPath to make it easier to pass literal paths #6732

@mklement0

Description

@mklement0

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].txt

to:

Get-Item -lp tmp[0].txt  # wishful thinking

Note 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-FixedThe issue is fixed.WG-Cmdlets-Corecmdlets in the Microsoft.PowerShell.Core module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions