1

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?

5
  • Quote the entire ifconfig ... command in {...}? Commented Nov 9, 2015 at 21:47
  • 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) Commented Nov 9, 2015 at 21:49
  • 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. Commented Nov 9, 2015 at 21:53
  • Removed the stray ]. That was a SO typo. Commented Nov 9, 2015 at 21:54
  • How are you running that list of commands? Commented Nov 9, 2015 at 23:19

1 Answer 1

1

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

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

2 Comments

@EtanReisner: wrapping the argument to awk in braces will not interfere with variable expansion in the argument to grep.
I understand what this answer was intending to say now. It should, in light of my comment and the response, be written more clearly and explicitly. In that it should explain what the issue is more specifically. Why changing the single quotes to {} (in place) will help. etc.

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.