hancock
hancock

Reputation: 23

How to get string in Tcl expansion substitution

To follow up with an earlier question using Tcl version 8.5 I have:

set defs {}
array set options $::argv
set git_ver $options(-git_ver)
lappend defs {-verilog_define GIT_VERSION=${git_ver}}
foreach i $defs { puts $i }

What I get from puts is:

-verilog_define GIT_VERSION=${git_ver}

But how do I get the string representation of my variable git_ver?

Upvotes: 0

Views: 459

Answers (1)

slebetman
slebetman

Reputation: 113866

Use double quotes instead of braces:

lappend defs "-verilog_define GIT_VERSION=${git_ver}"

Alternatively you can use the subst command to make braces act like double quotes:

lappend defs [subst {-verilog_define GIT_VERSION=${git_ver}}]

In Tcl, double quotes and braces do the same thing - group words. The only difference is that double quotes perform substitutions and braces don't.

Upvotes: 1

Related Questions