Now that we have the environment setup we’re going to write the traditional Hello World program. In this tutorial, all text associated with a Tcl command is bolded like this. All of the examples can be easily copied to your clipboard by hovering over the example code box and clicking the word “copy” that appears in the upper right-hand corner of the box. You can then paste the code in the coding widget at the bottom of this tutorial and run the code.
The command to output text to the window or console is
puts argument1
where
puts Hello
puts World!
puts "Hello World!"
puts {Hello World! with braces}
Notice that commands are delineated by new lines and therefore do not require a termination character.
Comments in Tcl are started using the # character. A comment can either exist on its own line or it can follow a command. However, if the comment follows a command then the command must be terminated with
#I’m a comment living on my own line
puts "Something meaningful"; #Notice the semicolon before this comment
To create your own program make a file called hello.tcl using your favorite text editor and type any of the previous commands (just to make sure that you save it as a .tcl file). Then execute the script by typing tclsh hello.tcl.
Exercise
Think you understand how puts works? Correct the following piece of code and get it to run. Try printing your name or favorite phrase.