How to Get Command History by Cursor Key in Linux Tclsh

How to get Command history by cursor key in Linux tclsh

You want access to the readline library, you can do that with rlwrap:

$ rlwrap tclsh

Useful options are -c for file name completion, and -f to add words from a file to the completion list:

$ rlwrap -cf my_complete_file tclsh

Since you almost always want to use rlwrap, adding a shell alias is useful:

alias tclsh='rlwrap tclsh'

How to get command line history in tkcon using the arrow keys?

UPDATING TO VERSION 2.7 resolved the problem. For version 2.5 I found a patch here.

How to increase command history size for tcl shell

Looks like you want history keep $biggerNumber -- http://www.tcl-lang.org/man/tcl8.6/TclCmd/history.htm

Depending on what platform you use, you might like rlwrap which gives you all the readline line editing goodies: arrow keys for history, etc.

alias tclsh='rlwrap tclsh'

Or, Tkcon is a good choice too.

How to use the left and right arrow keys in the tclsh interactive shell (Ubuntu 14.04)?

The behaviour isn't buggy. It is inconvenient yes.

To get editing in a shell, usually the GNU readline library is used. If a program doesn't use that library, you don't have that feature.

For tclsh there are licensing reasons (GPL vs. BSD style Tcl license), which make it inconvenient to add readline support directly to tclsh for all those platforms where readline is not part of the operating system (nearly everything but Linux).

You can use the Ubuntu rlwrap package to still get the editing you want.
Install rlwrap:

sudo apt-get install rlwrap

And use it to run tclsh with command line editing:

rlwrap -c tclsh

Another option would be to use the Tk based shell tkcon, which provides a bit more options as a Tcl shell, its available as a ubuntu package too.

Expanding my own answer: You can also build and use tclreadline, as a package in your .tclshrc.

How do I find the path to the tclsh running my script?

Just found it by myself: It's

info nameofexecutable

Get the version of TCL from the command-line?

This might sound too simplistic, but if you made a script file that contained the commands:

puts $tcl_version

And then ran tclsh sillyscript.tcl, that would execute on all platforms, assuming binary is in PATH. It certainly isn't fancy or flashy, or even neat, but it satisfies that requirement AFAIK.

====

I got curious, so I tried it and without the quotes:

echo puts $tcl_version;exit 0 | tclsh

Executes just fine on my windows box... maybe platform detection prior to the TCL detection is an option?



Related Topics



Leave a reply



Submit