LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Problem with executing a hell command from tcl (https://www.linuxquestions.org/questions/programming-9/problem-with-executing-a-hell-command-from-tcl-4175502943/)

Jykke 04-25-2014 05:23 AM

Problem with executing a hell command from tcl
 
I ain't a tcl crack but I am trying to improve the situation. I want to execute a linux shell command:
exec grep Title [lindex $argv 0] | awk '{print $2}' > tmp.txt
so far so good, but I get a message:
Error in startup script: can't read "2": no such variable
while executing
"exec grep Title [lindex $argv 0] | awk '{print $2}' > tmp.txt"
(file "/home/q275880/tcl/quick_plot.tcl" line 7)

well yes, I want to pass the $2 in such a form to linux shell but somehow tcl
takes it as its own variable. I already tried putting the command in quotes and
stuff, unfortunately with little success.

Any ideas?

ntubski 04-25-2014 09:56 AM

WORKING WITH QUOTED ARGUMENTS:

Quote:

When translating a command from a Unix shell invocation, care should be taken over the fact that single quote characters have no special significance to Tcl. Thus:

Code:

awk '{sum += $1} END {print sum}' numbers.list
would be translated into something like:
Code:

exec awk {{sum += $1} END {print sum}} numbers.list

So I think you want
Code:

exec grep Title [lindex $argv 0] | awk {{print $2}} > tmp.txt


All times are GMT -5. The time now is 04:39 PM.