Question: I would like to understand the basics of how to write and execute Tcl program on UNIX / Linux OS. Can you explain it with a simple example?
Answer: In this article, let us review very quickly how to write a basic Hello World Tcl program and execute tcl program on Linux or Unix OS.
1. Write a Hello World Tcl Program
Create the helloworld program using the Vim editor as shown below.
$ vim helloworld.tcl #!/usr/bin/tclsh # hello world sample program puts "Hello, World !"
Note: Comment in Tcl starts with #.
2. Make sure Tcl interpreter is installed on your system
Make sure Tcl interpreter is installed on your system as shown below.
$ whereis tclsh tclsh: /usr/bin/tclsh /usr/bin/tclsh8.4 /usr/share/man/man1/tclsh.1.gz
Installing tcl interpreter
If you don’t have tcl interpreter, install it as shown below.
$ sudo apt-get install tcl8.4
3. Execute Tcl Program
You can either execute using “tclsh helloworld.tcl” or “./helloworld.tcl”.
$ tclsh helloworld.tcl Hello World! ( or ) $ chmod u+x helloworld.tcl $ ./helloworld.tcl Hello World!
Note: As Tcl is an interpreted language, you don’t have the compilation step similar to the C program.