LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-15-2005, 09:01 AM   #1
powah
Member
 
Registered: Mar 2005
Distribution: FC, Gentoo
Posts: 276

Rep: Reputation: 30
use file content as tcl script parameters


My tcl script require two input parameters.
I want to use this tcl script both interactively and also pass the content of a file to it as input.

This is the tcl script.
#!/usr/bin/tclsh
set name [lindex $argv 0]
set phone [lindex $argv 1]
puts "name $name phone $phone\n"

if {$name == ""} {
puts "name is empty\n"
exit
}

if {$phone == ""} {
puts "phone is empty\n"
exit
}

# the rest of tcl script ...


Running the tcl script interactively:
# t.tcl john 2221234
name john phone 2221234


How to pass the content of a file to it as input?

This does not work because each line of the file is treated as one parameter, not two parameters:

data.txt is
john 2221234

# cat data.txt | xargs -i -t t.tcl {}
t.tcl john 2221234
name john 2221234 phone

phone is empty
 
Old 07-15-2005, 09:55 AM   #2
Quigi
Member
 
Registered: Mar 2003
Location: Cambridge, MA, USA
Distribution: Ubuntu (Dapper and Heron)
Posts: 377

Rep: Reputation: 31
Use
Code:
cat data.txt | xargs t.tcl
or simply
Code:
t.tcl `cat data.txt`
The xargs man page says about -i:
Quote:
Also, unquoted blanks do not terminate arguments.
So that's what broke your example. I cannot figure out what -t does.
 
Old 07-15-2005, 10:49 AM   #3
powah
Member
 
Registered: Mar 2005
Distribution: FC, Gentoo
Posts: 276

Original Poster
Rep: Reputation: 30
Code:
t.tcl `cat data.txt`
does not work if data.txt has more than one line.
e.g.
john 2221234
peter 1234567

"-t" (--verbose) print the command line on the standard error output before executing it.

Thanks.

Quote:
Originally posted by Quigi
Use
Code:
cat data.txt | xargs t.tcl
or simply
Code:
t.tcl `cat data.txt`
The xargs man page says about -i:

So that's what broke your example. I cannot figure out what -t does.

Last edited by powah; 07-15-2005 at 12:33 PM.
 
Old 07-16-2005, 11:10 AM   #4
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
You'd be better off modifying your script to accept either command line arguments, or stdin. Then you'd have the best of both worlds, and be able to use something like:
Code:
t.tcl < data.txt
to feed large amounts of data in.

Last edited by eddiebaby1023; 07-16-2005 at 11:16 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameters to a shell script neocookie Linux - General 5 10-20-2005 11:44 AM
Passing parameters to bash script Kamikazee Programming 4 10-01-2005 06:41 AM
safe script parameters Guttorm Programming 1 03-04-2005 12:19 PM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 11:00 AM
How to register a Tcl script as a service? vlbaranov Linux - Newbie 2 06-01-2004 10:14 AM


All times are GMT -5. The time now is 03:44 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration