代码之家  ›  专栏  ›  技术社区  ›  avramch

该术语在cmder/powershell中无法识别为cmdlet函数脚本文件或可操作程序

  •  1
  • avramch  · 技术社区  · 9 年前

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

    文件如下所示

    # 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“sub C:\Windows\System32\drivers\etc\hosts”中编写时,它可以工作。问题是什么?

    1 回复  |  直到 9 年前
        1
  •  3
  •   Mathias R. Jessen    9 年前

    在PowerShell中,别名是到 -不仅仅是表达。

    如果你愿意 hosts 要在Sublime中打开主机文件,请改为定义函数:

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

    与相同 .. www

    function .. { cd .. }
    function www { cd d:\wamp\www }
    
    推荐文章