【发布时间】:2019-01-10 09:23:31
【问题描述】:
假设我在命令行打错字:
whih foo
Powershell 返回:
whih : The term 'whih' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ whih mocha
+ ~~~~
+ CategoryInfo : ObjectNotFound: (whih:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
长消息对脚本很有用,但对于交互式 shell 使用,我想用更短的东西来包装它,比如:
'whih' isn't a cmdlet, function, script file, or operable program.
我可以包装错误并将其更改为更短的内容吗?
【问题讨论】:
-
不得不问,但我会假设 try 块不是您想要的(为此目的而设计的),并且您希望更改消息的实际措辞
-
@Matt 没错,它是用于交互式使用的。所以是的,我不想将每个命令都包装在
try块中。只是为$profile寻找东西
标签: powershell command-line powershell-core