TCL - Question regarding Braces {}

Hello everyone,

What is the difference between these two tcl commands:

(A) --> puts "ERROR!!! ${current_name}/${opt} is not found."
(B) --> puts "ERROR!!! $current_name/$opt is not found."

Are the braces needed to be put? Or both A and B has the same output?

if current_name string has space in it, you will see the difference.

1 Like

I've test to set the current_name to a string with spaces in it,
running both A and B produces the same result with no difference.

Wondering why the writer of the script writes out A instead of B, since both produce the same result?

ok, second, if there are two var defined, current_name and current, if no Braces with $Bcurrent_name, you maybe don't get the expect result.

When expanding a shell variable, the braces aren't needed unless the character following the variable name could be interpreted to be part of the name. So: $current_name/$opt produces exactly the same results as ${current_name}/${opt} , but ${current_name}_abc/${opt}_def is not at all the same as $current_name_abc/$opt_def .

1 Like

Thanks guys for the help..
Finally understand the reason