在Windows PowerShell中设置GCC的别名

ice*_*man 2 c powershell alias gcc c99

我正在尝试在Windows PowerShell中设置一个"gcc99"别名,它等于"gcc -std = C99 -pedantic -Wall".我们的想法是使用更少的击键来确保GCC以c99模式运行.(我已尽力使以下帖子中的指南适应Windows PowerShell:在GCC中设置std = c99标志)

当我在设置这样的别名(下面的图1)后尝试编译时,我收到一个错误.作为参考,如果我使用扩展命令进行编译,我不会收到此错误(参见下面的图2).作为测试,我尝试将gc99设置为"gcc"的别名(没有其他值)并且它工作正常(参见下面的3).请忽略我在代码中尚未解决的许多警告:)

有什么建议?

(我不确定为什么我的标题没有出现在下面的图片中.我正在使用自动创建的图片格式,例如,对于第一张图片:" 标题 "后面跟着" 1:链接"下一行.)

图1:尝试通过设置为

图表2:通过

图表3:通过设置为

Ans*_*ers 6

PowerShell中的别名与Unix shell中的别名不同.您只能为cmdlet,函数或程序的名称添加别名,而不包括参数.引用自Get-Help Set-Alias:

NAME
    Set-Alias

SYNOPSIS
    Creates or changes an alias (alternate name) for a cmdlet or other command
    element in the current Windows PowerShell session.


SYNTAX
    Set-Alias [-Name]  [-Value]  [-Description ] [-Force]
    [-Option ] [-PassThru] [-Scope ] [-Confirm]
    [-WhatIf] []


DESCRIPTION
    The Set-Alias cmdlet creates or changes an alias (alternate name) for a
    cmdlet or for a command element, such as a function, a script, a file,
    or other executable. You can also use Set-Alias to reassign a current alias
    to a new command, or to change any of the properties of an alias, such as
    its description. Unless you add the alias to the Windows PowerShell profile,
    the changes to an alias are lost when you exit the session or close Windows
    PowerShell.
Run Code Online (Sandbox Code Playgroud)

使用默认参数集运行外部程序可以做的是将默认设置定义为数组并运行如下所示的程序:

$CARGS = '-std=C99', '-pedantic', '-Wall'
gcc $CARGS -more arguments here ...
Run Code Online (Sandbox Code Playgroud)

正如@ChrisN在下面的评论中建议的那样,如果您希望$CARGS在所有PowerShell实例中预定义变量,则可以将其添加到自定义PowerShell配置文件(例如,%UserProfile%\Documents\Windows­PowerShell\profile.ps1为您的用户).