在Windows PowerShell设置别名GCC [英] Setting alias for gcc in Windows Powershell
问题描述
我试图建立在Windows PowerShell中gcc99的别名,等于为gcc -std = C99 -pedantic -Wall。该想法是使用较少的键击,以确保的gcc在C99模式下运行。 (我已经尽我所能在下面的帖子Windows PowerShell来适应原则:设置在GCC 性病= C99标志)
I'm trying to set up a "gcc99" alias in Windows Powershell which is equal to "gcc -std=C99 -pedantic -Wall". The idea is to use fewer keystrokes to ensure that gcc is running in c99 mode. (I've tried my best to adapt the guidelines in the following post to Windows Powershell: Setting std=c99 flag in GCC)
当我尝试建立这样一个别名(如下图1)经过编译,我收到一个错误。作为参考,如果我使用扩展命令编译(如下图2)我没有收到此错误。作为测试,我尝试设置GC99作为海湾合作委员会(无附加价值)的别名,它工作得很好(图3下)。请忽略的警告,我还没有在code,以解决:)
When I try to compile after setting up such an alias (exhibit 1 below), I receive an error. As reference, I don't receive this error if I use the extended command to compile (exhibit 2 below). As a test, I tried setting gc99 as an alias for "gcc" (no additional values) and it worked fine (exhibit 3 below). Please ignore the many warnings which I have yet to address in code :)
有什么建议?
(我不知道为什么我的标题没有显示为下面的图片我使用的照片自动创建的格式,例如,第一个形象:的标题,其次是的 1 :链接下一行)
(I'm not sure why my captions aren't showing up for the images below. I'm using the auto-created format for pictures, e.g., for the first image: "Caption" followed by "1: link" on the next line.)
推荐答案
别名在PowerShell中距离和Unix shell别名不同。您只能别名cmdlet,函数或程序的名称,不包括参数。从 获取帮助设置消除锯齿$ C $报价C>
:
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 ...
由于@ChrisN在下面的意见建议,如果你想变量 $ CARGS
$ P $在所有的PowerShell的情况下对定义,您可以将其添加到定制PowerShell配置(如%USERPROFILE %\\文档\\ WindowsPowerShell \\ profile.ps1
为您的用户)。
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\WindowsPowerShell\profile.ps1
for your user).
这篇关于在Windows PowerShell设置别名GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!