This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: pass bash variable as argument to gcc
- From: Arkadiusz Drabczyk <arkadiusz at drabczyk dot org>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 29 Oct 2015 13:49:55 +0000 (UTC)
- Subject: Re: pass bash variable as argument to gcc
- Authentication-results: sourceware.org; auth=none
- References: <1446123464157-1199673 dot post at n5 dot nabble dot com>
On 2015-10-29, staticx <mohamedboussaa3@gmail.com> wrote:
> I wonder if I can pass the content of a bash variable as an argument to gcc.
> My variable is a list of optimization options like $var="-opt1 -opt2 -opt3"
> gcc $var test.c -o object.o didn't work
What do you mean by `didn't work'? This worked for me:
$ ll
total 4.0K
-rw-r--r-- 1 ja ja 405 Oct 29 14:33 main.c
$ export VAR="main.c -o PROG -O2 -g"
$ gcc $VAR
$ ll
total 16K
-rw-r--r-- 1 ja ja 405 Oct 29 14:33 main.c
-rwxr-xr-x 1 ja ja 11K Oct 29 14:43 PROG
You just can't do:
$ VAR="main.c -o PROG -O2 -g" gcc $VAR
gcc: fatal error: no input files
compilation terminated.
because $VAR will expanded at the very beginning before it is defined
and will be empty. This not gcc problem, it's how Bash works.
--
Arkadiusz Drabczyk <arkadiusz@drabczyk.org>