Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing command-line arguments to Tcl

Status
Not open for further replies.

GeorgeLewis

Programmer
Nov 19, 1999
1
US
Is there any way to pass command-line arguments to a script?<br>
<br>
For example, I am writing a parsing program and would like to specify the settings.<br>
I don't want to delve into creating and reading values from checkbox, radio button, or text widgets, etc.<br>
in Tk if I don't have to do it.<br>
<br>
The simple solution to me would be to use the command-line. But, I don't know if Tcl allows you to<br>
use the command-line. For example, I would call my parser to print all the procedures in a Tcl script:<br>
Parser.tcl
 
The command line arguments are available inside a script<br>
as global variables:<br>
<br>
argv0 is the name of the script<br>
argv is a list of the arguments<br>
argc is the number of arguments<br>
(equal to [llength $argv])<br>
<br>
Hence the following script should print out the arguments:<br>
<br>
#!/bin/sh<br>
# The next line runs tclsh, passing the \<br>
# arguments of this shell script to it. \<br>
exec tclsh &quot;$0&quot; &quot;$@&quot;<br>
<br>
puts &quot;Command line arguments: $argv ($argc)&quot;<br>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top