pass bash variable as argument to gcc

Jeff Epler
Fri Oct 30 02:44:00 GMT 2015

It is useful to understand how the shell behaves.  The common bash shell
is intended to be a superset of the standard Unix shell, which is
described in this standards document
-- though by web search, you will be able to find other explanations of
the unix shell which may be easier to read and understand.

Anyhow, we are interested in how simple commands are parsed and
executed, in order to understand why your original alternative did not

Notice the following statement about a simple command that has both a
variable assignment and a command name:

    If no command name results, or if the command name is a special built-in
    or function, variable assignments shall affect the current execution
    environment. Otherwise, the variable assignments shall be exported for
    the execution environment of the command and *shall not affect the
    current execution environment* except as a side-effect of the expansions
    performed in step 4. In this case it is unspecified:
        (emphasis mine)

This requirement of the standard is why your original command did not
work as you desired.

Here are some simple uses of 'echo' that show several cases of how shell
variables and environment variables behave -- the last one is
particularly surprising to someone not familiar with the
rules of the Unix shell:

$ unset unsetvar
$ echo "${unsetvar-unset}"
$ var="x y z"
$ echo "${var-unset}"
x y z
$ unset ENVVAR
$ ENVVAR="x y z" echo "${ENVVAR-unset}"
$ ENVVAR="x y z"; export ENVVAR
$ ENVVAR="a b c" echo "${ENVVAR-unset}"
x y z


More information about the Gcc-help mailing list