2016-08-16 32 views
1

我使用cmder,並在cmder/config/user-profile.ps1的user-profile.ps1中爲powershell創建了一些別名。該術語不被識別爲cmdlet函數腳本文件或可操作程序...在cmder/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' 和 '主機'。當我寫 '主人',例如,它給了我像

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 \等\主機',它的工作原理。問題是什麼?

回答

2

在PowerShell中,別名是映射到的命令 - 不僅僅是任何類型的表達式。

如果你想hosts在崇高打開hosts文件,定義的函數:

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

同樣的,..www

function .. { cd .. } 
function www { cd d:\wamp\www } 
+0

明白了。現在它可以工作。非常感謝! – avramch

相關問題