tksh.1 revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9

Tksh Man Page
Jeffrey Korn
Jan 10, 1996

tksh 1
S
NAME
tksh - Tcl/Tk extension for KornShell
SYNOPSIS
ksh [ \(+-abcefhikmnoprstuvxCD ] [ -R file ] [ \(+-o option ] .\|.\|. [ - ] [ arg .\|.\|. ]

tksh [ \(+-abcefhikmnoprstuvxCD ] [ -R file ] [ \(+-o option ] .\|.\|. [ - ] [ arg .\|.\|. ]

tclksh [ \(+-abcefhikmnoprstuvxCD ] [ -R file ] [ \(+-o option ] .\|.\|. [ - ] [ arg .\|.\|. ]

DESCRIPTION

Tksh is a version of KornShell with a set of additional builtin commands that provide ksh with the functionality of Tcl/Tk. With Tksh, KornShell can be used to write graphical interface scripts with the Tk library. Tksh can also interpret Tcl scripts for backward compatibility.

Invoked as ksh, Tksh will initialize neither Tcl nor Tk.

Invoked as tksh, Tksh will initialize both Tcl and Tk.

Invoked as tclksh, Tksh will initialize Tcl but not Tk.

"BUILTIN COMMANDS"

Invoked as tclksh, Tksh is initialized to be used with Tcl only (not Tk). As a result, a set of builtin commands are added that provide Tcl functionality. Tcl built-in commands are added, but their names begin with tcl_ to avoid conflicts with ksh and UNIX commands. In addition, the source command is added, which can be used to interpret Tcl scripts.

Invoked as tksh, Tksh is initialized to be used with both Tcl and Tk. This does everything that tclksh does, and initializes Tk as well. Initializing Tk includes adding the set of Tk commands (their names are unmodified) and initializing a main window.

The following builtins are created when Tcl is initialized:

tcl_name The equivalent to the Tcl command name. Currently supported commands: tcl_append tcl_array tcl_break tcl_case tcl_catch tcl_close tcl_concat tcl_continue tcl_eof tcl_error tcl_eval tcl_exec tcl_expr tcl_file tcl_flush tcl_for tcl_foreach tcl_format tcl_gets tcl_glob tcl_global tcl_if tcl_incr tcl_info tcl_join tcl_lappend tcl_lindex tcl_linsert tcl_list tcl_llength tcl_lrange tcl_lreplace tcl_lsearch tcl_lsort tcl_open tcl_pid tcl_proc tcl_puts tcl_read tcl_regexp tcl_regsub tcl_rename tcl_return tcl_scan tcl_seek tcl_set tcl_split tcl_string tcl_subst tcl_switch tcl_tell tcl_time tcl_trace tcl_unset tcl_uplevel tcl_upvar tcl_while. See the Tcl manual pages for more information.

source [file] The source command can be used to read and interpret a Tcl script. If a file is specified, the file will be read and interpreted. If it is not specified, standard input will be used. source is equivalent to . in ksh, but parses Tcl instead of shell.

When source is used, commands read are first looked up as tcl_name (where name is the command name) and then as name in the builtin command table. This way, Tcl scripts do not have to be modified to prepend tcl_ to Tcl commands.

The following builtins are created when Tk is initialized:

tkloop If Tk has been initialized, tkloop can be used to enter a Tk event loop. This command must be used at the end of any Tk script to prevent ksh from exiting. tkloop returns when there are no more windows or exit has been called.

Tk commands All Tk builtin commands (button, pack, bind, etc.). See the Tk manual pages for more information.

"VARIABLES"
Variables in ksh and Tcl/Tk share the same name space. Any variable can have both ksh disciplines and Tcl traces set. In addition to the variable initialized by Tcl/Tk (such as $tcl_version and $tk_version), Tksh defines the following:

$tksh_version This variable is initialized to the version of Tksh being used. This variable can be used in the ksh envfile to do any initialization specific to Tksh.

"DIFFERENCES"
The following differences should be noted with using Tcl or Tk commands with KornShell:

Quoting Arguments to Tcl/Tk commands should be quoted with shell syntax.

Example:

Tcl: bind <1> clickFunction

Ksh: bind '<1>' clickFunction

Arrays Tcl/Tk commands that specify the name of a variable that is an element of an array must use Tcl/Tk notation. Thus, specifying the variable a[b] must be done as a(b) in a Tcl/Tk command.

Example:

Tcl: set foo(bar) "Hello" ; message .m -textvar foo(bar)

Ksh: foo[bar]="Hello" ; message .m -textvar 'foo(bar)'

The array command does not work the same way that it does in Tcl. Walking through an array does not guarantee that the indicies will be in sorted order. This will cause the array test to fail, but the functionality is the same as in Tcl.

Lists Tcl uses lists to deal with a collection of strings, whereas ksh usually uses arrays. In ksh, a Tcl list can be represented as a string if the elements of the list are quoted in such a way that splitting the list in ksh (by processing the arguments) yields the elements of the list. For example, the Tcl list {a {b c} d} corresponds to 'a "b c" d' in Tksh. By issuing the command "eval set -- 'a "b c" d'" we can obtain the list elements with $1, $2, $3, etc.

The Tcl builtin list commands (lindex. llength, etc.) operate on Tcl style lists only, and will not work with a ksh list.
A Tcl style list can be used in a shell script by using the built-in command setlist [array-name]. setlist will convert a Tcl style list into the array array-name or the positional parameters ($1, $2, etc.) if no array is specified.

Command strings Some Tk commands take arguments that are strings to be interpreted. For example, the button command allows a string to be specified (with the -command option) that will be executed when the button is pressed. Tksh needs to decide whether the string should be parsed as a Tcl command or a shell command. Normally, Tksh will use the current mode of the parser, but this is not always desirable. Therefore, the following rules are used to decide the parser of a command string:

4 1) If a command string has as its first line "#!ksh", ksh will be used. If the first line is "#!tcl", Tcl will be used.

2) Otherwise, the string is parsed with the "current" parser. This will be Tcl when the calling command is invoked from the Tcl parser (the current parser is set to Tcl during the source command).

3) Builtin commands have an associated parser with them. Thus, if a Tcl proc is called from ksh, the parser will switch from ksh to Tcl.

4) Tksh replaces the Tk bind command (which binds a command string to a window event) with a modified version which automatically places the appropriate line to the beginning of the specified string (if one hasn't already been specified).

Results In Tcl, commands return both a string and a completion code. In ksh, commands return only a completion code. The means by which strings are returned in ksh is by printing them to standard output. Thus, Tksh prints the contents of the result string to standard output upon successful completion of a Tcl command, and prints the result string to standard error otherwise. This allows command substitution in ksh behave like it does in Tcl. Since Tcl does not normally print the result of a command, Tksh only prints the result of a Tcl command if it is called inside command substitution.

"THE TCL LIBRARY"
The environment variable $TKSH_LIBRARY is used to set the location of the Tksh libraries (there is a default value that has been compiled into Tksh). This should not be the same directory as the Tcl library. Tksh has its own set of initialization scripts.
"NOT IMPLEMENTED"
The following features of Tcl are not yet implemented in Tksh:

4 1) Some of the functionality in the Tcl UNIX commands.

2) The Tcl auto_path mechanism.

3) tclFileTable - This is a global variable that is defined in Tcl and used in Tk. Since ksh uses a different file table, this table is not supported.

"Tksh As a Ksh Extension"

If Tksh is compiled as a shared library, it can be dynamically loaded into ksh93. In order to do this, the Tksh library must be in a directory in the $LD_LIBRARY_PATH variable. If it not, the command "builtin -f tksh_library_name" can be used.

There are two builtin commands that exist to initialize Tcl or Tk. tclinit initializes only Tcl, and tkinit initializes Tcl and Tk. To use either of these commands, the builtin command must be used (e.g., "builtin tkinit").

Tksh will not work well interactively as a shared library if you are using a version of ksh earlier than 93e.

"BUGS"
Sometimes, invoking a Tcl proc from ksh using $(...) will crash when a variable with a discipline is changed.
"SEE ALSO"
ksh(1), tclsh(1), wish(1)

http://www.cs.princeton.edu/~jlk/tksh