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.
Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.Get the Linux Sysadmin Course Now!
If you enjoyed this article, you might also like..
|
|
|
|






My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 4 comments… read them below or add one }
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…..