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.
Comments on this entry are closed.
tlc is no. 36 in this top:
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
Tcl must be programming’s best kept secret. Don’t forget Tcl’s other secrets:
Tk is a Tcl extension (most other dynamic languages load a small Tcl to access Tk)
SQLite is a Tcl extension.
Expect is a Tcl extension.
Can be used as an interactive shell.
There are a huge number of other extensions available.
Tcl has one of the only single-file deployment models (and the best – tclkit).
No need to install Tcl/Tk. Use tclkit for single-file install.
Tcl is fully cross platform, same scripts run on pretty much any hardware/OS.
One step one to I hit enter after I type this – vim helloworld.tcl? Apparently not. I am not being successful. Can you help? I guess I need step by step when to hit enter and how to save and then run program in proper director or do I need to create a directory prior to creating the program. Sorry, this is my first work with tcl or unix.
thank u…..
thanks for sharing… it was quite helpful