Command line arguments
With any scripting language, the ability to provide arguments allows you to write a script that accepts arguments to perform a specific function.
As previously discussed, Tcl has several global variables to allow for the passing of command line arguments. The number of command line arguments to a Tcl script is passed as the global variable argc
. The name of a Tcl script is passed to the script as the global variable argv0
, and the arguments are passed as a list in the argv
global variable.
Launching a Tcl script
In the following example we will invoke a Tcl script contained within a text file. This script will accept any number of arguments and print out the script name, the count of the arguments and the values contained ...
Get Tcl/Tk 8.5 Programming Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.