How can I prevent powershell from treating YabaDabaDoo as an alias for Get-YabaDabaDoo?

╄→尐↘猪︶ㄣ 提交于 2020-12-08 05:05:30

问题


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.CommandNotFoundAction for 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!