0

I am using tcl tk to create a GUI application. I am referring to Ousterhout book. One of the sample code says:

In the examples so far you have typed Tcl commands interactively to tclsh or wish. You can also place commands into script files and invoke the script files just like shell scripts. To do this for the hello world example, place the following text in a file named hello:

   #!/usr/local/bin/wish -f
   button .b -text "Hello, world!" -command exit
   pack .b

This script is the same as the one you typed earlier except for the first line. As far as wish is concerned this line is a comment but if you make the file executable (type “chmod 775 hello” to your shell, for example) you can then invoke the file directly by typing hello to your shell. When you do this the system will invoke wish, passing it the file as a script to interpret. Wish will display the same window shown in Figure 2.1 and wait for you to interact with it. In this case you will not be able to type commands interactively to wish; all you can do is click on the button. Note: This script will only work if wish is installed in /usr/local/bin. If wish has been installed somewhere else then you’ll need to change the first line to reflect its location on your system.

On my system I have tried this:

root@c3-redsuren-vm01:/# which wish
/usr/bin/wish
root@c3-redsuren-vm01:/# cd ~
root@c3-redsuren-vm01:~# cd Documents/scripts/

root@c3-redsuren-vm01:~/Documents/scripts# cat hello
#!/usr/bin/wish -f
button .b -text "Hello, world!" -command exit
pack .b

When i try to invoke the script it says -bash not found..

root@c3-redsuren-vm01:~/Documents/scripts# hello
-bash: hello: command not found
Barmar
  • 741,623
  • 53
  • 500
  • 612
redpy
  • 143
  • 5
  • 2
    What does this have to do with Python? – Barmar Mar 18 '21 at 19:19
  • 4
    Make sure `~/Documents/scripts` is in your `$PATH` variable, and the script has execute permission. – Barmar Mar 18 '21 at 19:20
  • 1
    While I'm closing this with a duplicate that is about shell scripts, the same thing is true for tcl scripts (and Python scripts, and every other kind of script). You need to (1) make sure your file is marked executable (`chmod +x hello`); (2) make sure its location is in your PATH; and (3) make sure its shebang is valid. You're proving that (3) is correct in this question, but not covering (1) or (2). – Charles Duffy Mar 18 '21 at 19:22
  • 1
    Use `./hello` to run a program in your current working directory... – Shawn Mar 18 '21 at 19:47
  • We usually recommend starting executable Tcl scripts with `#!/usr/bin/env tclsh` or `#!/usr/bin/env wish` to get sensible PATH searching with minimal effort. – Donal Fellows Mar 18 '21 at 21:38
  • @Barmar thanks and thanks everyone.. got it working now :) – redpy Mar 19 '21 at 16:14

0 Answers0