Windows和OS X实现之间PowerShell别名'ls'和'dir'的不同行为是否有原因? [英] Is there a reason for the different behaviour of PowerShell aliases 'ls' and 'dir' between the windows and OS X implementations
问题描述
有人知道以下两种情况下输出差异的原因吗?
Does anyone know the reason for the difference in output between the below 2 cases?
别名ls
的输出与OSX上别名dir
的输出不同.在Help Get-Content -Examples
的PowerShell帮助中显示的示例中:
The output from alias ls
differs from the output of alias dir
on OSX. In an example shown in the PowerShell help for Help Get-Content -Examples
:
dir ./*.txt | foreach {Get-Content $_ -Head 1; Get-Content $_ -Tail 1}
按照示例工作.但是,如果将dir
替换为ls
:
works as per the example. However, if dir
is replaced with ls
:
ls ./*.txt | foreach {Get-Content $_ -Head 1; Get-Content $_ -Tail 1}
返回错误:
ls:./*.txt:没有这样的文件或目录
ls: ./*.txt: No such file or directory
以上两种情况在Windows 10上的PowerShell v5中都得到相同的结果.
Both the above cases give the same result in PowerShell v5 on Windows 10.
此观察是否有错误?
推荐答案
您似乎正在调用命令/bin/ls
(/usr/bin/ls
?)而不是PowerShell别名ls
,即使别名应优先于外部命令.验证别名是否已实际定义:
You seem to be invoking the command /bin/ls
(/usr/bin/ls
?) rather than the PowerShell alias ls
, even though an alias should take precedence over an external command. Verify that the alias is actually defined:
Get-Alias -Name ls
这篇关于Windows和OS X实现之间PowerShell别名'ls'和'dir'的不同行为是否有原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!