[英]How to pass arguments to Unix-like commands (via MinGW) in PowerShell
I'm using MinGW on my Windows machine, and when I use it with the command-prompt
, things work as expected: 我在Windows机器上使用MinGW,当我将其与command-prompt
一起使用时,事情可以按预期进行:
ls
lists the visible files ls
列出可见文件 ls -a
lists all files, etc ls -a
列出所有文件,等等 But, when I fire up Powershell, it keeps throwing errors when I pass arguments to my commands as so: 但是,当我启动Powershell时,将参数传递给命令时,它始终会引发错误:
D:\>ls -al .
Get-ChildItem : A parameter cannot be found that matches parameter name 'al'.
At line:1 char:4
+ ls -al .
+ ~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Powershell.Commands.GetChildItemCommand
What can I do to use all my MinGW/msys commands properly via Powershell? 如何通过Powershell正确使用我的所有MinGW / msys命令?
ls
is an alias in Powershell for the get-childitem
command. ls
是Powershell中get-childitem
命令的别名。 If you want to run an external command called ls
you will need to force Powershell to ignore its own ls
command. 如果要运行名为ls
的外部命令,则需要强制Powershell忽略其自己的ls
命令。
You could try running ls.exe
, or specify the path to the MinGW command, or undefine the Powershell alias. 您可以尝试运行ls.exe
,或者指定MinGW命令的路径,或者ls.exe
定义Powershell别名。 Or learn to use the options for Powershell's own ls
command instead. 或者学习改为使用Powershell自己的ls
命令的选项。
The nearest Powershell equivalent to ls -al
would be ls -Force
This will display all hidden and system files and Powershell's default output for ls
looks somewhat like the ls -l
format anyway. 相当于ls -al
的最接近Powershell将是ls -Force
这将显示所有隐藏文件和系统文件,而Powershell的ls
默认输出无论如何看起来都类似于ls -l
格式。
You can check which command will be run using Powershell's get-command
which does a similar job to which
(or use gcm
as shorthand for less typing: 您可以使用Powershell的get-command
检查将运行哪个命令,该命令的工作与which
类似(或使用gcm
作为简化形式,以减少输入:
PS C:\Users\IEUser> get-command ls.exe
CommandType Name Version Source
----------- ---- ------- ------
Application ls.exe 0.0.0.0 C:\Program Files\OpenSSH\bin\ls.exe
PS C:\Users\IEUser> get-command ls
CommandType Name Version Source
----------- ---- ------- ------
Alias ls -> Get-ChildItem
PS C:\Users\IEUser> gcm ls
CommandType Name Version Source
----------- ---- ------- ------
Alias ls -> Get-ChildItem
PS C:\Users\IEUser> gcm ls.exe
CommandType Name Version Source
----------- ---- ------- ------
Application ls.exe 0.0.0.0 C:\Program Files\OpenSSH\bin\ls.exe
and if you don't want to learn a new command: 并且如果您不想学习新命令:
PS C:\Users\IEUser> set-alias which gcm
PS C:\Users\IEUser> which ls
CommandType Name Version Source
----------- ---- ------- ------
Alias ls -> Get-ChildItem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.