1

i was sourcing a tcl script file and could not pass the parameter. ie.

source test.tcl param1 param2

where in test.tcl, it uses param1 and param2 to print as string

Note: I need to source tcl script only.. Not any other

puts "param1                       :  $1"
puts "param2                       :  $2"

1 Answer 1

2

You can set argv:

set origargv $::argv
set ::argv [list -param1 x -param2 y]
source myscript

The sourced script can access the parameters from argv as usual.

Sign up to request clarification or add additional context in comments.

1 Comment

I'd use a try…finally to restore the arguments… if necessary. I usually don't write my scripts to need that; most of my code files just declare procedures, namespaces and classes, and have no meaningful arguments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.