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」を除くすべてのエイリアスが適切に機能します。たとえば、「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 では、エイリアスは、あらゆる種類の式だけでなく、コマンドへのマッピングです。

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 に答える