Generate terminal escape sequences from Tcl

One of my readers (who unfortunately prefered to stay anonymous, so I cannot give credit where it's due) figured out how to output escape sequences from IOS Tclsh: you have execute terminal international command first.

For example, to clear the screen and display red heading text, use the following commands:

exec terminal international;
puts "\033\[2J\033\[H\033\[1;31mHeader text\033\[m"
Obviously, you could easily use this functionality to build a nice full-screen menu system.
Notes
  • To output the ESC character, use the \033 code within the double quotes;
  • To output the left angle bracket, you have to use the \[ sequences, otherwise Tcl interprets the bracket as start of an expression;
  • The ANSI escape sequences (recognized by most terminal emulators) are documented on Wikipedia;
You can find more Tclsh-related information in the Tclsh on Cisco IOS tutorial. Sample Tclsh scripts are available in the Tclsh script library. If you need expert help in planning, developing or deploying Tclsh scripts in your network, contact the author.

3 comments:

  1. Hi,

    I have just started tracking your blog, I am no IOS wizard. I would like to ask you what exactly one gets from using tclsh ? Is it like having a UNIX shell inside IOS i.e. such as tcsh ?

    Can you nutshell summarise tclsh please.

    -aW

    ReplyDelete
  2. alex, tcl is a scripting language.

    tclsh is an environment in wich you can execute tcl scripts in.

    Its not a shell.

    ReplyDelete
  3. "alias exec" on steroids, but running in its own environment? This is how I interpreted this!

    ReplyDelete

You don't have to log in to post a comment, but please do provide your real name/URL. Anonymous comments might get deleted.

Ivan Pepelnjak, CCIE#1354, is the chief technology advisor for NIL Data Communications. He has been designing and implementing large-scale data communications networks as well as teaching and writing books about advanced technologies since 1990. See his full profile, contact him or follow @ioshints on Twitter.