Setting alias for GCC in Windows PowerShell

半世苍凉 提交于 2019-11-27 09:49:35

Aliases in PowerShell are different from aliases in Unix shells. You can only alias the name of a cmdlet, function or program, not include parameters. Quoting from 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.

What you can do to run an external program with a default set of arguments is to define that default set as an array and run the program like this:

$CARGS = '-std=C99', '-pedantic', '-Wall'
gcc $CARGS -more arguments here ...

As @ChrisN suggested in the comments below, if you want the variable $CARGS pre-defined in all your PowerShell instances, you can add it to a custom PowerShell profile (e.g. %UserProfile%\Documents\Windows­PowerShell\profile.ps1 for your user).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!