How to convert command.env tcl lists with spaces into working env strings

Steven Smith steve.t.smith at
Fri Sep 2 04:07:59 UTC 2022

Thank you.

I ended up refactoring the Portfile to use the default configure/build/destroot functionality.

I was not aware that a side effect of writing one’s own build {} etc. blocks is that it blows away the automatic setting of environments variables in build.env.

Thanks for suggesting—that may be useful some day.


> On Sep 1, 2022, at 5:06 PM, Joshua Root <jmr at> wrote:
> On 2022-9-1 21:51 , Steven Smith wrote:
>> How does one convert a build.env list into a working string for sh env?
>> If I specify this build.env
>>> build.env-append \
>>>     CC=${ <>< <>>} \
>>> "CFLAGS=${configure.cflags} [get_canonical_archflags cc]"
>> and later say something like
>>> system "env ${build.env}"
>> This tcl string with braces ‘{…}’ is passed to the shell, which breaks:
>>> env CC=/usr/bin/clang {CFLAGS=-Os -arch x86_64}
>> Rather, I need a port file command that converts build.env to:
>>> env CC=/usr/bin/clang CFLAGS="-Os -arch x86_64"
> Ideally you would run this as part of build.cmd (or some other command) and have MacPorts set up the environment directly for you. But if you have to do it this way, something like this should work:
> foreach e ${build.env} {
>    lappend envargs [shellescape $e]
> }
> system "env [join $envargs] ..."
> - Josh

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3898 bytes
Desc: not available
URL: <>

More information about the macports-dev mailing list