Re: is tcl a reasonable alternative to unix shell scripts?



Charles Russell wrote:
For years I have been using Bourne shell scripts for housekeeping tasks
(archiving files, converting files, etc.) but this is a tricky and messy
way to do things. I've been wondering whether one of the scripting
languages may be a simpler way to write housekeeping utilities. The
simple lisp-like syntax of tcl appeals to me. I note that python and
ruby have equivalents to the unix "find" command, but I cannot find on
skimming the tcl documentation that it has a good set of tools for
manipulating the file system. Are they there? Would tcl scripts be
simpler and/or more readable than shell scripts for writing simple
utilities? Does anyone have an example handy, e.g. for an incremental
backup utility?

Jeff and Michael have made some good suggestions. I'd just like to
remind you that the "find" command is not normall part of your shell.
So just do in Tcl what you usually do in your shell script: execute the
find command!

# assigning result to a variable:
set x [exec find]

# parse result into a proper list and assign it to a variable:
set y [split [exec find] \n]

Generally, unless you're on a system where the regular unix commands
are completely built-in to the shell and not available as executables
(and I know some embedded systems where this is indeed the case), Tcl
can do anything shell scripts can do with a much cleaner syntax and a
much more powerful substitution engine. Not to mention that you also
get to use things which you normally can't do in a regular shell script
like opening a socket etc..

My suggestion is when in a hurry and you need to get the job done then
there is nothing wrong with using Tcl simply as a glue language to
execute regular Unix commands like the "find" example above. As you get
more comfortable with the Tcl core functions and extensions (you really
should install tcllib at the very least) you'll find the built in
functions much easier to work with and in some cases much more
powerful. But exec (and open) is your friend - use them to make the
learning curve as gentle as possible.

.



Relevant Pages

  • Re: Is Tcl work for large programs?
    ... Small tcl scripts or small shell scripts. ... I like that perl has 'perl -d' ...
    (comp.lang.tcl)
  • Re: problems with apps communicating with each other (was Re: Whats TCL related to?)
    ... > Svenn Are Bjerkem wrote: ... this is not a tcl problem is it? ... Synopsys where Tcl/Tk is used as the command language. ... I use code-browser on windows to do tcl scripts. ...
    (comp.lang.tcl)
  • Re: executing a configure script from a tcl scrip
    ... I am having problem to launch the configure script from tcl. ... When working on windows I get the "can't find ... I never compiled Tcl on windows but I do know that configure scripts ... what program you run a Command Window will popup. ...
    (comp.lang.tcl)
  • Re: ANNOUNCE: Tcl/Tk 8.5.0 RELEASED
    ... The Tcl Core Team is pleased to announce the 8.5.0 releases of the Tcl ... Tcl/Tk 8.5.0 sources are freely available as open source from the Tcl ... A summary of the new features visible to Tcl scripts in the Tcl/Tk 8.5 ... Add a Command ...
    (comp.lang.tcl)
  • ntlib.cmd (Advanced NT/2K/XP/K3 Command Library)
    ... The latest Advanced Command Library for Windows NT/2K/XP/K3 ... MAINTAINABLE shell scripts without adding any third-party software. ... They are constructed entirely of builtin commands ...
    (microsoft.public.win2000.cmdprompt.admin)