1

我使用cmder,并在cmder/config/user-profile.ps1 中的user-profile.ps1 中为powershell 创建了一些别名。

文件看起来像这样

# Use this file to run your own startup commands
New-Alias subl "C:\Program Files\Sublime Text 3\sublime_text.exe"
New-Alias mysql "D:\wamp\bin\mysql\mysql5.7.11\bin\mysql.exe"
New-Alias o Invoke-Item
New-Alias c Clear-Host
New-Alias hosts "subl $env:windir\System32\drivers\etc\hosts"
New-Alias .. "cd .."
New-Alias www "cd d:\wamp\www"

除了“..”、“www”和“hosts”之外,所有别名都可以正常工作。例如,当我写“主机”时,它会给我一个错误,例如

The term "subl C:\Windows\System32\drivers\etc\hosts" is not recognized as cmdlet function script file or operable program
At line:1 char:1
+ hosts
+ ~~~~~
    + CategoryInfo          : ObjectNotFound: (subl C:\Windows...ivers\etc\hosts:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

但是,当我在 cmder 'subl C:\Windows\System32\drivers\etc\hosts' 中写入时,它可以工作。问题是什么?

4

1 回答 1

3

在 PowerShell 中,别名是对命令的映射,而不仅仅是对任何类型的表达式。

如果要hosts在 Sublime 中打开 hosts 文件,请定义一个函数:

function hosts { subl $env:windir\System32\drivers\etc\hosts }

..和相同www

function .. { cd .. }
function www { cd d:\wamp\www }
于 2016-08-16T17:36:10.880 回答