问题
Please, observe:
C:\> Get-Date
Tuesday, February 4, 2020 5:50:55 PM
C:\> Date
Tuesday, February 4, 2020 5:50:57 PM
C:\> Get-Content C:\Users\mkharitonov\.bashrc
alias ls='ls --color=auto -alhX'
alias npp="C:/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"
C:\> Content C:\Users\mkharitonov\.bashrc
alias ls='ls --color=auto -alhX'
alias npp="C:/Program\ Files\ \(x86\)/Notepad++/notepad++.exe"
C:\>
I do not want this behavior. How can one control it?
回答1:
As of PowerShell Core 7.0.0-rc.2, you cannot prevent this behavior, which is by (costly) design: Get is the implied default verb, so submitting Content ultimately invokes Get-Content, for instance - unless a command explicitly named Content exists too.
A member of the PowerShell team has openly considered removing this feature, given that it is both obscure and costly in terms of performance (in addition to being incompletely implemented):
Note that this command lookup behavior is not limited to cmdlets - it works for any command including native commands.
It is also very expensive - we first search normally (including the PATH), and if that fails, we repeat the search prepending
Get-.Personally, I'd rather remove this misfeature than formalize it. We could provide a handler for
$ExecutionContext.InvokeCommand.CommandNotFoundActionfor folks that are unwilling to fix old scripts that rely on this odd feature.
来源:https://stackoverflow.com/questions/60066704/how-can-i-prevent-powershell-from-treating-yabadabadoo-as-an-alias-for-get-yabad