无法使用字符串在 PowerShell 中设置别名

Sal*_*ood 3 powershell

我尝试通过运行在 PowerShell 中设置别名Set-Alias -Name artisan -Value 'php aritsan',尽管命令运行成功,但当我调用别名时,会发生以下错误:

artisan : The term 'php aritsan' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ artisan
+ ~~~~~~~
    + CategoryInfo          : ObjectNotFound: (php aritsan:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Run Code Online (Sandbox Code Playgroud)

正确的方法是什么?

PS:artisan是当前目录下的文件。该文件是用laravel框架打包的

Har*_*rza 6

这将帮助您在 Windows PowerShell 中全局创建“php artisan”的别名。只需按照以下步骤操作即可完成。

  1. 首先使用win+S搜索powershell并以管理员身份运行,然后粘贴此代码并按Enter键。

    if (!(Test-Path -Path $PROFILE )) {New-Item -Type File -Path $PROFILE -Force }

  2. 然后运行这个命令。

    记事本$配置文件

  3. 将打开一个记事本文件。将此代码粘贴到记事本文件中,然后按 ctrl+S

    函数 CD32($arg1,$arg2,$arg3,$arg4,$arg5) {php artisan $arg1 $arg2 $arg3 $arg4 $arg5} Set-Alias -Name pa -Value CD32

  4. 最后将此命令粘贴到您的 powershell 上并按 Enter 键。

    设置-ExecutionPolicy -ExecutionPolicy RemoteSigned

一切都完成了。现在,您可以在 Windows powershell 中全局使用“pa”作为“php artisan”的别名。

在这里,我在 VS Code PowerShell 上使用“pa”。