1
votes

I need to run a few commands from terminal via a TCL script. This TCL script works fine.

set cmd_list [list {mkdir testdir} {cd testdir} ]
set dataportInterface "eth0"
lappend cmd_list [list ifconfig -a | grep -m 1 $dataportInterface]

However, as soon as I add the awk command, it starts failing. Error is "Failed : extra characters after close-brace".

lappend cmd_list [list ifconfig -a | grep -m 1 $dataportInterface | awk 'BEGIN {FS="[:]"} { print $1 } END {}' | xargs -t ethtool -S]

I have tried several possibilities, but none of them work. For example, if I try

lappend cmd_list {  }

then, $dataportInterface's value eth0 is not taken.

I tried putting a \ in front of all special characters (: " ' [ { and that threw the error $1 not recognized. I put the awk command in {{ brackets and that didn't work either. (error: doesn't recognize {{awk)

What is the correct way to go about this, and why?

1
Quote the entire ifconfig ... command in {...}? - Etan Reisner
In that case, $dataportInterface is not changed to eth0. However, if I hardcode eth0, it works. (But that's not what I'm looking for) - sbhatla
Fair enough. You'll need to use something to format your string then. Also you appear to have a stray ] after $dataportInterface in that ifconfig command. - Etan Reisner
Removed the stray ]. That was a SO typo. - sbhatla
How are you running that list of commands? - Donal Fellows

1 Answers

1
votes

Single quotes have no significance to Tcl - try changing '...' to {...}