1
votes

Basically what I am trying to do is to pipe a tcl command within a zsh shell. Most common piping are grep, awk and sed for text manipulation.

With perl and ruby there is the -e option which allows to execute statements directly from the shell without writing a script on a file.

Is it possible to achieve the same thing in tcl?

Thank you.

2
Not exactly, but expect has -e. - Johannes Kuhn
On my system expect works with the -c option. - milarepa

2 Answers

3
votes

tclsh does not have anything like -e; it's a very simple wrapper round the Tcl library.

You can simulate with a script like this:

apply {{} {
    global argv0 argv argc
    if {[lindex $argv 0] eq "-e"} {
        set script [lindex $argv 1]
        set argv [lrange $argv 2 end]
        incr argc -2
        uplevel #0 $script
    } else {
        set argv0 [lindex $argv 0]
        set argv [lrange $argv 1 end]
        incr argc -1
        uplevel #0 [list source $argv0]
    }
}}

If you make a script with that in called tclhelper.tcl and define a shell alias:

alias tcl='tclsh tclhelper.tcl'

Then you'll be able to do:

tcl -e "puts [info patchlevel]"

and see things work.

1
votes

It could be done by piping your tcl one liner to tclsh with |, ex:

echo 'puts "do_something"' | tclsh