如何在PowerShell别名中运行多个命令

13

我想在$profile文件中为PowerShell添加一个别名。

Set-Alias regrunt grunt;g aa;g cm 'regrunted';g ps;
当我运行regrunt时,只有第一个命令被运行。如何使这个别名运行所有的命令?
PS:请不要评论“不要提交压缩文件”,我们都经历过这个。
2个回答

26

很遗憾,PowerShell中的别名只能用于单个命令。

您需要定义一个函数来运行多个命令:

function regrunt {
    grunt;g aa;g cm 'regrunted';g ps;
}

7

PowerShell中的别名是为了简单重命名命令而设计的。只能有一个命令,没有参数。如果想要实现您想要的功能,请编写一个函数。

function regrunt {
  grunt
  g aa
  g cm 'regrunted'
  g ps
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接