Tcl Hello World Example: How To Write, Compile and Execute Tcl Program on Linux OS

by Ramesh Natarajan on April 9, 2010

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 Sysadmin Course 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..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 5 comments… read them below or add one }

1 al mic April 9, 2010 at 2:27 am
2 Al April 9, 2010 at 3:35 am

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.

3 Karl September 17, 2010 at 2:39 pm

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.

4 SAMYNATHAN August 16, 2012 at 5:09 am

thank u…..

5 Milind Shende November 11, 2013 at 7:26 am

thanks for sharing… it was quite helpful

Leave a Comment

Previous post:

Next post: