Wednesday, 15 January 2014

bash - Passing arguments from command line into a tcl script -



bash - Passing arguments from command line into a tcl script -

i have tcl script has many parameters defined arguments. intend create job file can execute .tcl script different combinations of parameters without manual intervention.

what mean following:

job file (run.sh):

./main.tcl arg1 arg2 arg3 arg4 ./main.tcl arg1 arg3 arg5

now want able pass command line argument array "argv" each run mentioned in run.sh array main.tcl script options set accordingly within script prior execution.

is there way link .sh script , .tcl script?

per online document here:

the method numbers can passed into, , used script, follows.

argc argv argv0

all tcl scripts have access 3 predefined variables. $argc - number items of arguments passed script. $argv - list of arguments. $argv0 - name of script.

to utilize arguments, script re-written follows.

if { $argc != 2 } { puts "the add.tcl script requires 2 numbers inputed." puts "for example, tclsh add.tcl 2 5". puts "please seek again." } else { puts [expr [lindex $argv 0] + [lindex $argv 1]] }

bash tcl

No comments:

Post a Comment