Portfile question (actually, tcl question)

Ryan Schmidt ryandesign at macports.org
Fri Sep 20 23:30:05 UTC 2019



On Sep 20, 2019, at 15:42, Gerben Wierda wrote:


> On 20 Sep 2019, at 18:29, Dr M J Carter wrote:
> 
>> On Fri, Sep 20, 2019 at 05:33:02PM +0200, Gerben Wierda wrote:
>>>   I’m new to tcl, so maybe this is simple, but I haven’t been able to solve
>>>   it.
>>> 
>>> startupitem.start      "[variant_isset "withdnsserver"] ? "port load dns-server\n\t" : "" ] port load clamav-server
>>> \tport load apache-solr8
>>> \tport load redis
>>> \tport load dcc
>>> \tport load postfix
>>> \tport load dovecot2
>>> \tport load rspamd
>>> \tport load logrotate"
>>> 
>>> 
>>>   Now, obviously, this doesn’t work because of all the double quotes inside
>>>   double quotes. 
>>>   How do I do this without using variables?
>> 
>> Backslash-quote them, thus: "foo \"bar\" baz" -> foo "bar" baz
>> 
>> Hope this helps.
> 
> Actually, it doesn’t because the result is
> 
>         0 ? "port load dns-server
>         " : "" ] port load clamav-server
>         port load apache-solr8
>         port load redis
>         port load dcc
> 
> and not
> 
>         port load clamav-server
>         port load apache-solr8
>         port load redis
>         port load dcc
> 
> What also doesn’t work is (with a variable):
> 
> set startupitemstring   [variant_isset "withdnsserver" ? "port load dns-server\n\t" : ""]
> append startupitemstring "port load clamav-server
> \tport load apache-solr8
> \tport load redis
> \tport load dcc
> \tport load postfix
> \tport load dovecot2
> \tport load rspamd
> \tport load logrotate"
> startupitem.start       "$startupitemstring"
> 
> which gets me:
> 
> Error: Unable to open port: wrong # args: should be "variant_isset name"
> 
> And 
> 
> set startupitemstring   [variant_isset "withdnsserver"] ? "port load dns-server\n\t" : ""
> 
> gets me:
> 
> Error: Unable to open port: wrong # args: should be "set varName ?newValue?"
> 
> And
> 
> set startupitemstring	[[variant_isset "withdnsserver"] ? "port load dns-server\n\t" : ""]
> 
> gets me:
> 
> Error: Unable to open port: invalid command name "0"
> 
> Obviously, I do not understand tcl, but I also am unable to find any tcsl ternary operator example that uses strings like this.

It looks like to use a ternary operator in Tcl you have to be inside an [expr ...]




More information about the macports-users mailing list