Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sourcing a script and passing arguments?

14 views
Skip to first unread message

Helmut Giese

unread,
Dec 15, 2001, 12:21:11 PM12/15/01
to
Hello out there,
during development I would often find it useful to 'source' a script
and pass it (command line) arguments at the same time: a fast way to
test something.
This of course does not work ('source' will only accept a filename),
so I either have to set some global variables before sourcing or edit
the script - both methods being a bit annoying.

Is there another way? What do you do in this situation?

Glad for any hints or ideas.
Helmut

Mark G. Saye

unread,
Dec 15, 2001, 1:03:25 PM12/15/01
to
Helmut Giese wrote:
>
> Hello out there,
> during development I would often find it useful to 'source' a script
> and pass it (command line) arguments at the same time: a fast way to
> test something.
> This of course does not work ('source' will only accept a filename),
> so I either have to set some global variables before sourcing or edit
> the script - both methods being a bit annoying.

Agreed.

> Is there another way? What do you do in this situation?

You could always create a new procedure to set the global variable(s)
and source the file e.g.

#--------------
# file: argv.tcl
set script [file join [pwd] [info script]]
puts "source '$script'"
puts "argv0='$::argv0'"
puts "argv ='$::argv'"
puts "argc ='[llength $::argv]'"
#--------------

#--------------
# file: src.tcl
proc src {file args} {
set argv $::argv
set ::argv $args
uplevel #0 source $file
set ::argv $argv
}

puts "argv0='$argv0'"
puts "argv ='$argv'"
puts "argc ='[llength $argv]'"

src argv.tcl abc def ghi jkl

puts "argv0='$argv0'"
puts "argv ='$argv'"
puts "argc ='[llength $argv]'"
#--------------

Then run:
> tclsh src.tcl qwe rty
argv0='src.tcl'
argv ='qwe rty'
argc ='2'
source '/local/home/msaye/dev/tmp/argv.tcl'
argv0='src.tcl'
argv ='abc def ghi jkl'
argc ='4'
argv0='src.tcl'
argv ='qwe rty'
argc ='2'


Don't know if this helps any ... ;-}

Mark /

--
Mark G. Saye
mark...@yahoo.com

Helmut Giese

unread,
Dec 15, 2001, 4:09:59 PM12/15/01
to
On Sat, 15 Dec 2001 10:03:25 -0800, "Mark G. Saye"
<mark...@yahoo.com> wrote:

>You could always create a new procedure to set the global variable(s)
>and source the file e.g.
>

Hi Mark,
that's a nice idea, I like it. Thanks for sharing it.
Helmut

PS: After looking at it for a while, I liked it even more. Only a
couple of lines to add missing functionality - just the Tcl way.
Now if I could only come up with this kind of thing myself ...

Christian Brunner

unread,
Dec 17, 2001, 5:07:47 AM12/17/01
to hgi...@ratiosoft.com
Hi,

a simple way to change things quickly (RAD: rapid application
development) is to paste commands, procs or even classes using either
the X selection (Un*x) or Edit-Paste (in Tcl's Windows console).

We're using a special debug-loglevel in our apps to open a console
window for investigations and maintenance. IMHO, one of Tcl's charming
features is changing functionality/implementation details during the
runtime of an application.

Regards,
Christian.

--
CSK Software AG
Christian Brunner | Tel: +49 69 50952-234
Holzhausenstrasse 44 | Fax: +49 69 50952-299
D-60322 Frankfurt/Main | cbru...@csksoftware.com

lvi...@yahoo.com

unread,
Dec 18, 2001, 10:50:56 AM12/18/01
to

According to Christian Brunner <cbru...@csksoftware.com>:
:We're using a special debug-loglevel in our apps to open a console

:window for investigations and maintenance. IMHO, one of Tcl's charming
:features is changing functionality/implementation details during the
:runtime of an application.

The thing I always worry about in situations like this is that someone
will make a change to the running code and forget/neglect/intentionally not
make the same change to the source code. As soon as the power cycles,
a cpu board has to be replaced, whatever you no longer are running the
same image...

--
"I know of vanishingly few people ... who choose to use ksh." "I'm a minority!"
<URL: mailto:lvi...@cas.org> <URL: http://www.purl.org/NET/lvirden/>
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.

0 new messages