On Unix, a file called $HOME/.tclshrc , and on Windows, a file called $HOME\tclshrc.tcl , will be read by tclsh when it is started interactively.

Note that it is NOT read if tclsh is started with a command file.

Please feel free to add examples of useful things one can do with this facility.

  1. perform a package require on one of the pure-tcl readline2 type packages, providing a different command line history functionality.
  2. Set tcl_prompt1 or tcl_prompt2
  3. Create useful interp aliases.
  4. Customize proc unknown to, e.g., use expr as a last resort so that tclsh can be used as a calculator.
  5. I often need to use the Tclx package, so I place the package require statement in the .tclshrc file
  6. I placed this line in the .tclshrc to remind myself which version the shell is (there are at least two versions at work): puts "TCL $tcl_patchLevel\n"

Lavin - 2009-12-24 12:58:52

How can I invoke tclsh for interactive execution, but specify file(s) to be sourced before issuing the first command prompt? TIA, -- Mark

AMG: Put "source whatever.tcl" in your .tclshrc. Or put the code you'd like to be executed directly in .tclshrc.

MGS [2010-05-14]: Maybe prompt can help you?

See also The RC File.