Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TCL set Special Characters in a string

Tags:

tcl

I want to set in TCL the below error message as a variable and compare with the error message from a network switch, by-passing the special characters

Use [slot/port] or ["portname"] or [slot/*] or [*].

I tried in this way

set x "Use \[slot/port] or \["portname"] or \[slot/\*] or \[\*]."

but I am getting the following message while running my script:

extra characters after close-quote while executing

Please help. Thank you!

like image 788
code_trot Avatar asked Sep 18 '25 12:09

code_trot


1 Answers

If you use double quotes, you also have to escape "inner" quotes:

set x "Use \[slot/port] or \[\"portname\"] or \[slot/*] or \[*]."

Or use braces and avoid escaping altogether

set x {Use [slot/port] or ["portname"] or [slot/*] or [*].}

See Tcl's 12 syntax rules, numbers 4 and 6

like image 101
glenn jackman Avatar answered Sep 20 '25 05:09

glenn jackman