Tcl: Gotchas
From FVue
Single quote (') is not significant
A single quote cannot be used to group words. If a string has more than one word, you must enclose the string in double quotes or braces ({}).
Single quote characters have no special significance to Tcl.
See also: http://www.tcl.tk/man/tcl8.5/tutorial/Tcl1.html.
Tcl is not bash
Consider the following script t.sh:
#!/bin/sh echo 1=$1, 2=$2
This will happen if it's executed from bash (chmod u+x t.sh):
bash$ args="foo bar"; ./t.sh $args # Outputs: 1=foo, 2=bar
Now lets try the same with tclsh:
tclsh% set args "foo bar"; ./t.sh $args ; # Outputs: 1=foo bar, 2=
Tcl sees args as a single variable. You have to use eval if you want the bash effect:
tclsh% eval ./t.sh $args ; # Outputs: 1=foo, 2=bar
Or as the ActiveTcl manual states:
- [11] Substitution and word boundaries.
- Substitutions do not affect the word boundaries of a command. For example, during variable substitution the entire value of the variable becomes part of a single word, even if the variable's value contains spaces.
See also
- Frequently Made Mistakesâ„¢ in Tcl
- Informative, long list of Tcl gotchas
- wjduquette.com: Will's Guide To Success with Tcl 8.x Namespaces and Packages
- Best practices for using namespaces and packages, including Style Guide
Advertisement