How to check that a string contains a number in Tcl
Archive - Originally posted on "The Horse's Mouth" - 2005-08-06 10:44:19 - Graham EllisIn Tcl, all variables hold strings. If you perform an arithmetic operation such as an expr, an incr or a numeric comparision, the incoming strings are converted into a numbers internally, the calculations are done, and the results are converted back to strings and saved. It might not sound very efficient, but it's nice and simple and it works very well for most scripting requirements.

First option - you can use the catch command. With catch, you'll attempt to perform the Tcl operation, and if it fails you'll get a false (0) result returned by the catch command to tell you that there's been an error, instead of simply having the program crash. This allows you to do your own error handling and (where appropriate) recovery.
See: Example of catch
Second option - you can check your incoming strings using the string is command that was added at version 8.1 of Tcl so should be on all your systems by now!
For example:
string is integer -strict $abcd
will return a true value if the variable $abcd contains (strictly) an integer, and false otherwise. (without the strict option things like leading and trailing white space will be allowed)
The integer keyword is known as a class - there are about a dozen possibilities including double for a floating point number and boolean to test for any valid Tcl boolean string such as 0, false, 1, true.