| |||||||||||
executable tcl script's creating problem Posted by saga (saga), 1 February 2007 hi, My question is how to create an executable tcl file in unix. That is a tcl script can be run directly as follows. $ ./scriptname.tcl I tried some settings, but failed. Please help check the following log and give your advices. Thanks. the following settings refer to unix book or something from internet. +++++++++++++++++++++++++++ ex. 1. $ more file4.tcl #!/usr/bin/sh # the next line restarts using tclsh exec /cph/ActiveTcl8.4/bin/tclsh8.4 "$0" ${1+"$@"} # here is a simple command for test puts stdout " try test " exit $ ./file4.tcl can't read "0": no such variable while executing "exec /cph/ActiveTcl8.4/bin/tclsh8.4 "$0" ${1+"$@"} " (file "./file4.tcl" line 4) ex. 2. $ more file1.tcl #! /cph/ActiveTcl8.4/bin/tclsh puts stdout "\n ------ script programming ------\n" $ ./file1.tcl ./file1.tcl: puts: not found ex. 3. $ more file2.tcl #! /usr/bin/sh exec /cph/ActiveTcl8.4/bin/tclsh8.4 puts stdout " #! /usr/bin/sh" $ ./file2.tcl % % % exit // after running file2.tcl, "%" prompt appears, but no command is running, so manually input "exit" to logout tclsh. $ ### notes: usually, we use "#!" to give a interpreter for the subsequent commands. Here that seems unuseful. +++++++++++++++++++++++++ Posted by admin (Graham Ellis), 2 February 2007 Try it putting the full Tcl path onto the initail #! line - it should workPosted by saga (saga), 2 February 2007 I had used the absolute path in the first line of .tcl file.A little queer. i. for example ex.2, if using "tclsh file1.tcl" command, it's ok. Here is the result. $ tclsh file1.tcl ------ script programming ------ ii. for example ex.3 $ more file2.tcl #! /usr/bin/sh exec /cph/ActiveTcl8.4/bin/tclsh8.4 puts stdout " #! /usr/bin/sh" $ ./file2.tcl % // here "%" indicate tclsh is running. BUT it doesn't interpret the subsequent commands. % % exit // after running file2.tcl, "%" prompt appears, but no command is running, so manually input "exit" to logout tclsh. $ Posted by saga (saga), 2 February 2007 I don't know why. It indeed should work when adding "#!shell absolute path" as a lot of documents say.Maybe it is relate to operating system or other something. Since "tclsh filename.tcl" is ok, I will temporarily use this way to perform my scripts. Thanks. Posted by admin (Graham Ellis), 3 February 2007 Have you marked your script file as being executable with chmod?Posted by saga (saga), 5 February 2007 I have found where the problem is. I add a redundant blank line at the beginning of the script. "#!" must be added in the first line. I did a stupid thing when editing script. Thanks for your helping analyzing. below is a bad script and a good script. i. bad script $ ./file1.tcl ./file1.tcl: puts: not found $ more file1.tcl // here is an extra blank line. #!/cph/ActiveTcl8.4/bin/tclsh puts stdout "\n ------ script programming ------\n" ii. good script (no extra blank line at the beginning) $ ./file1.tcl ------ script programming ------ $ more file1.tcl #!/cph/ActiveTcl8.4/bin/tclsh puts stdout "\n ------ script programming ------\n" Posted by admin (Graham Ellis), 6 February 2007 Don't be too hard on yourself - that's VERY easily done!This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |