Version 2 of How can I get input from a user and then safely make use of it?

Updated 2003-09-02 14:20:12

Purpose: discuss general guidelines for gathering input and then making use of it in Tcl.


A new user often finds s/he has a problem when dealing with user input.

Sometimes, the problem is a file name with a space in it. Sometimes, the problem is a string with special characters like [ or $ .

On this page, please add notes to help a new programmer avoid these problems.


One important thing is to keep the type of the input string in mind as you code. While Tcl has the reputation of everything is a string, not every command expects all its arguments to be arbitrary strings. In the most obvious example, Tcl input or output commands which require a file handle expects that argument to be a string returned from an open type command. Just handing some arbitrary string is very likely not going to work.

Similarly, handing an arbitrary string to a command which expects an argument in a list format may very well not work either.

[Perhaps a real example of this will eventually surface, replacing this commenet, since my last attempt failed so miserably...]


Category Tutorial | Category Security