On 11/4/2010 11:41 AM, David Rysdam wrote:
> An agent or agents purporting to be Steven W. Orr said:
>> I have a stupid question in tcl that I'm just not getting. I'm hoping to get
>> lucky here.
>>
>> I have a script in tcl/expect that spawns su and needs to pass its arguments
>> to su.
>>
>> argv in tcl has the command line args. I lop off the first couple of args 
>> that
>> I need in my script via:
>>
>> set user [lindex $argv 0]
>> set passwd [lindex $argv 1]
>>
>> Then I want to pass the *rest* of the args to su. What I have is this:
>>
>> spawn su - $user -c "[lrange $argv 2 end]"
>>
>> If I call me script
>>
>> sss me secret 'pwd; ls'
>>
>> Then what happens is this:
>>
>> spawn su - swagent -c {pwd; ls;}
>> Password:
>> -bash: -c: line 0: syntax error near unexpected token `}'
>> -bash: -c: line 0: `{pwd; ls;}'
>>
>> I vershtumped about where the braces are coming from. found out that if I 
>> pass
>> a single command without any semicolon , it works ok.
>
> The braces are there because the result of the lrange is a list.  The
> way we handle this in our code (which may not be The Right Way) is by
> doing something this:
>
> set args [lrange $argv 2 end]
> eval {spawn su - $user -c} "$args"
>
> (I don't know if you need the quotes for either spawn or su, so those
> might be extraneous or need some special quoting or something.)
>
> Newer versions for Tcl (and therefore Expect?) also have an expand
> operator that probably does this better, but I don't know if you are
> using that.

I'm impressed. Thanks

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
_______________________________________________
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/

Reply via email to