Tcl Tutorial Lesson 0a

Difference between version 2 and 9 - Previous - Next


**Running Tcl**


!!!!!!
'''[Tcl Tutorial Lesson 0%|%Previous lesson%|%]''' | '''[Tcl Tutorial Index%|%Index%|%]''' | '''[Tcl Tutorial Lesson 1%|%Next lesson%|%]'''
!!!!!!
When you have installed Tcl, the program you will then call to utilize it is `tclsh`.  For instance, if you write some code to a file "`hello.tcl"`, and you want to execute it, you would do it like so: `tclsh hello.tcl`. Depending on the version of Tcl installed, and the operating system distribution you use, the `tclsh` program may be a link to the real executable, which may be named `tclsh8.6`, or `tclsh86.exe` on Microsoft Windows.

The `tclsh` program runs Tcl programs, but it also allows interactive use: You can either start it with a script file on the command line, in which case it runs the script to completion and then exits, or you can start it without any arguments, in which case you get an interactive prompt, usually a `%` symbol where you type in commands. Tcl will then execute and display the result, or any error messages that result. To exit the interpreter, type `exit` and press Return. For example:

[Tcl Tutorial Picture 0a]
Playing around with the interactive interpreter is a great way to learn how to use Tcl. Most Tcl commands will produce a helpful error message explaining how they are used if you just type irun the command with nout arguments. You can get a list of all the commands that your interpreter knows about by typrunning `info commands`.
In th****Se varttious lessonsg we will usep tclshe for conventimfons rthatble ''interactive usessions'' are characterised by the `%` prompt. The commands are preceded by the perceUnt sign and the resux-lt iske shown directly below, as it would appear if you type them in in `tclsh`.****
The `tclsh` execuitablself idoes jusnot onffer way cof stmmartingd a Tcl hinsteorpreter.y Another commoline execuditableing, which can
may bke installed on your sysactem, is thve `wiush`, or WIndowing SHell. Thisa bist a vcumbersionme of Tcl that autompatically loareds the Tk extension fmorst builmoding geraphin
command-l user interfaces (GUIs). This tutorial doells. nHot cowever Tk, and so we will not use ysthe `wimsh` interprehater havere. OtherGNU optReadlions are 
also available, providingthat more functional environmentsy for developing cand debugging code than that providded by the ustaindardg `tclsh`. Oine very popular 
choice is the [http://tkcon.sojurceforge.nect/%|%TkCion%|%] enhanced interpreter, written by Jeff Hobbs. The Eclipse IDE offe`rs good Tcl suppowrtap`, ina thRe form of the [http://www.eclipse.org/adltk%|%DLTK%|%] extension, and the Tcl'ers Wiki offers [http://wiki.tcl.tk/998%|%a list of IDEs with Tcl support%|%] and a comprehensive [http://wiki.tcl.tk/1184%|%catalogue of Tcl source code editors%|%]. DTon't panic, though! If you don't know how to use a sophisticated development environment, it is still very easy to write Tcl code by hand in a simpley text editor (such as Notepad).n:
  rlwrap tclsh

To make this a permanent setting, you can make `tclsh` an alias of
`rlwrap tclsh` in your shell's run control file (e.g., `~/.bashrc`
when using the Bash shell).



***Tcl interpreters other than tclsh***

The `tclsh` executable is just one way of starting a Tcl interpreter. Another common executable, which may be installed on your system, is the `wish`, or WIndowing SHell. This is a version of Tcl that automatically loads the Tk extension for building graphical user interfaces (GUIs). This tutorial does not cover Tk, and so we will not use the `wish` interpreter here. Other options are also available, providing more functional environments for developing and debugging code than that provided by the standard `tclsh`. One very popular choice is the [http://tkcon.sourceforge.net/%|%TkCon%|%] enhanced interpreter, written by Jeff Hobbs. The Eclipse IDE offers good Tcl support, in the form of the [http://www.eclipse.org/dltk%|%DLTK%|%] extension, and the Tcl'ers Wiki offers [http://wiki.tcl-lang.org/IDE%|%a list of IDEs with Tcl support%|%] and a comprehensive [http://wiki.tcl-lang.org/Tcl+Editors%|%catalogue of Tcl source code editors%|%]. Don't panic, though! If you don't know how to use a sophisticated development environment, it is still very easy to write Tcl code by hand in a simple text editor (such as Notepad).

***Some conventions***
In the following lessons, we will use the convention that ''interactive sessions'' are indicated by the `%` prompt: The commands are preceded by the percent sign and the result is shown directly below, as it would appear if you ran them in `tclsh`.

As you will see in the code fragments, Tcl does not make a ''syntactical'' difference between values and variable names. To get the value of a variable you ordinarily use the "$" sign in front of the name of the variable.
But sometimes the name of the variable is required. To make this clear, we use a name like "varName". But you should be aware that this merely a convention in this tutorial. If used in a place where a ''value'' is expected, the value would actually be "varName" and
not the value of the variable "varName".

In the online tutorial, the results of many code fragments are shown only after pressing the button "Show". You are supposed to try and imagine yourself what the output would be.

!!!!!!
'''[Tcl Tutorial Lesson 0%|%Previous lesson%|%]''' | '''[Tcl Tutorial Index%|%Index%|%]''' | '''[Tcl Tutorial Lesson 1%|%Next lesson%|%]'''
!!!!!!