Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[TCL] Command Line Arguments
06-06-2010, 05:32 AM
Post: #1
[TCL] Command Line Arguments
I commented well on this one. So I don't think much more of an explanation would be needed.

Code:
#!/usr/bin/tclsh

#Grabbing Command Line Arguments TCL
#Back_Track http://www.pro9ramming.com

puts "Number of Arguments $argc"
# If you program in C this may be familiar
# argc = argument count(number of arguments)

set i 1
#giving out variable(type int) a value
#We are preparing for our foreach loop

puts "Execution Statement: $argv0"
foreach arg $argv {
#For each argument in argv(argument variable)
#In C argv is an array of Strings(an array of Char arrays)
#So for each Argument in this puts the number then the actual
#arguments while incrementing i for good measure
puts "Arguments $i is $arg"
incr i

}

Sample Run:

steven@steven-laptop:~/Desktop$ ./Arg.tcl hello Pro9ramming.com!
Number of Arguments 2
Execution Statement: ./Arg.tcl
Arguments 1 is hello
Arguments 2 is Pro9ramming.com!


If ran as such
tclsh Arg.tcl

It will display the programs name

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: