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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get executing script name

Status
Not open for further replies.

need4weed

Programmer
Sep 1, 2009
2
GB
hi, i'd like to find out the executing scripts name. batch uses %0, python uses argv[0], php uses __FILE__ .... ect. what is tcl's way?

thanks! (i tried google)
 
Here is an example:

cmdargs.tcl
Code:
[COLOR=#0000ff]# command line arguments[/color]
[COLOR=#804040][b]set[/b][/color] script_name [COLOR=#008080]$argv0[/color]
[COLOR=#804040][b]set[/b][/color] cmd_arg01 [[COLOR=#804040][b]lindex[/b][/color] [COLOR=#008080]$argv[/color] [COLOR=#ff00ff]0[/color]]
[COLOR=#804040][b]set[/b][/color] cmd_arg02 [[COLOR=#804040][b]lindex[/b][/color] [COLOR=#008080]$argv[/color] [COLOR=#ff00ff]1[/color]]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"script_name = '$script_name'"[/color]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"cmd_arg01   = '$cmd_arg01'"[/color]
[COLOR=#804040][b]puts[/b][/color] [COLOR=#ff00ff]"cmd_arg02   = '$cmd_arg02'"[/color]
Output:
Code:
c:\Work>tclsh85 cmdargs.tcl foo bar
script_name = 'cmdargs.tcl'
cmd_arg01   = 'foo'
cmd_arg02   = 'bar'
 
Hi

Just two minor notes :
need4weed said:
batch uses %0, python uses argv[0], php uses __FILE__ .... ect.
Wrong. In PHP you should also use the $argv predefined reserved variable, not the __FILE__ magic constant.
need4weed said:
(i tried google)
Next time try the Tcl documentation too. It has the answer at tclvars.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top