简体   繁体   English

如何在PowerShell中将参数传递给类似Unix的命令(通过MinGW)

[英]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.

相关问题 适用于Windows的便携式unix环境 - Portable unix-like environment for Windows 如何在类似 Unix 的 Visual Studio Code 中的所有文件中制作所有行结尾 (EOL)? - How can I make all line endings (EOLs) in all files in Visual Studio Code, Unix-like? R:使用cat()获取类似Unix的linebreak LF写入文件 - R: Getting Unix-like linebreak LF writing files with cat() 在Windows和类Unix系统之间有区别的Makefile - Makefile that distincts between Windows and Unix-like systems 如何将参数传递给Windows上在MinGW下运行的bash脚本 - How to pass arguments to a bash script running under MinGW on Windows 如何通过Powershell启动过程将带引号的参数传递给提升的批处理脚本 - How to pass quoted arguments to elevated batch script via powershell Start-Process 如何在PowerShell中将参数传递给嵌入式脚本? - How to pass arguments to an inline script in PowerShell? 如何将 arguments 传递给远程 powershell 脚本? - How to pass arguments to a remote powershell script? 如何在jenkins构建过程中在批处理命令中传递特定参数 - how to pass specific arguments in batch commands during jenkins builds 如何使 Powershell 像 Linux/Unix 系统或“cmd” shell 一样自动完成? - How to make Powershell autocomplete like Linux/Unix systems or “cmd” shell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM