0

i work in Linux and i normally execute the following command in the shell:

SomeCommand <Standard params> <params of type A> <params of type B> > Out.log

Now i want to call this in a TCL script like so:

set ParamsA "-some params of type A"
set ParamsB "-some params of type B"
set AllParams "-moreStandardParams $ParamsA $ParamsB"
exec SomeCommand $AllParams > Out.log

i am having some hard time making this work, because no matter what i try i cant seem to make all the params visible to SomeCommand. what is the correct way of doing this? i am obviously new to TCL. what is the difference between "" [] {} and are there any other ways of enclosing the params? What is the rule with the white spaces pre and post parenthesis?

1

1 Answer 1

0

The basic problem is that exec takes a set of words as arguments and it is getting passed only one.

I like to use a list to build up the command line. Then for the actual exec, the list must be expanded into separate words. lists have an advantage that when they are converted to a string (e.g. $mylist), the canonicalized (string-ified, serialized) form will always convert back to the same list.

set cmd mycommand
lappend cmd -param1 p1
lappend cmd -param2 p2
if { $someoption } {
  lappend cmd -param3 p3
}
lappend cmd -debug

exec {*}$cmd > $outfile

If you are using an older version of Tcl, you will need to use the eval statement:

eval exec $cmd > $outfile

Edit: missed the other half of your question.

Double quotes enclose a string and allow interpolation of escaped characters and substitution of variables and commands:

 set cmd command
 "here is [string toupper my] $cmd\r\n"

Braces are similar to single quotes in algol-derived languages. They specify a string. No command and variable substitution is done. Backslash interpolation is not done:

 {here is [string toupper my] $cmd\r\n}

Brackets specify that the first word is a command and should be processed as a command.

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

Comments

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.