我刚刚安装了适用于 Linux 的 PowerShell 开源版本在 Arch Linux 上使用这powershell-git包裹从尿素尿率。当我尝试 PowerShell 的-Version
功能时,我得到以下信息:
PS /home/user> powershell -Version 5.1
-Version : The term '-Version' 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
+ -Version 5.1
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (-Version:String) [], CommandNot
FoundException
+ FullyQualifiedErrorId : CommandNotFoundException
如何解决这个问题?
答案1
PowerShell 是为 Windows 编写的,它假定底层文件系统不区分大小写。当您输入 PowerShell 命令时,程序会读取您输入的任何内容,然后将其与实际情况进行匹配应该成为并重新展示它。
这PowerShell 的帮助消息显示该选项为-Version
:
-Version
Starts the specified version of Windows PowerShell.
Enter a version number with the parameter, such as "-version 2.0".
错误消息表明它希望使用文件系统的全拼写名称概念找到匹配项。如果您使用帮助消息中指示的大小写混合名称,您可能会取得更好的成功。
答案2
在Ubuntu上似乎正常工作:
thufir@dur:~$
thufir@dur:~$ pwsh
PowerShell v6.0.1
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /home/thufir>
PS /home/thufir> $PSVersionTable.PSVersion
Major Minor Patch PreReleas BuildLabel
eLabel
----- ----- ----- --------- ----------
6 0 1
PS /home/thufir>
PS /home/thufir> get-host
Name : ConsoleHost
Version : 6.0.1
InstanceId : 914b71f4-0e73-461c-b1c3-f04753e5ed34
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : en-CA
CurrentUICulture : en-CA
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
PS /home/thufir>
PS /home/thufir> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.1
PSEdition Core
GitCommitId v6.0.1
OS Linux 4.13.0-32-generic #35-Ubuntu SMP Thu Jan 25 09:13:46 UTC 2018
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS /home/thufir>
PS /home/thufir> exit
thufir@dur:~$
thufir@dur:~$ pwsh hello_world.ps1
hello powershell world
thufir@dur:~$
thufir@dur:~$ ./hello_world.ps1
hello powershell world
thufir@dur:~$
thufir@dur:~$ cat hello_world.ps1
#!/usr/bin/pwsh -Command
"hello powershell world"
thufir@dur:~$
你必须澄清这个问题。您找不到 的版本pwsh
?