I am trying to use curly-braces to define a string { }
instead of double-quotes " "
, so that I don't have to escape several characters (such as $
, [
, ]
).
However, I am running into some problems when my string needs to contain a single {
within it.
I know that I can achieve this by simply using a double-quoted string and escape the {
, but how would I do it using a "curly-brace string"?
Eg.
I want to puts
the following string 'proc foo { } {' to stdout.
puts "proc foo \{ \} \{"
gives me the desired output: 'proc foo { } {'
However, puts { proc foo \{ \} \{ }
gives me: 'proc foo \{ \} \{' by literally printing the backslashes.
If I skip the backslashes, puts { proc foo { } {
, it complains about a missing brace.
Also, if the desired string has a matching closing-brace within it, it works fine.
puts { proc foo { } { } }
gives me the expected: 'proc foo { } { }'
What is the correct way to escape a single unmatched curly-brace in a "curly-brace string"?