I have a test.tcl (has all permissions) which contains the following-
#!/usr/bin/tclsh
puts "hello, world"This is how I'm executing my tcl script-
sudo source /opt/test.tclI got the output-
sudo: source: command not foundBut I checked the availability of source and sudo using whereis command and they were available-
$ whereis sudo
sudo: /usr/bin/sudo /usr/share/man/man8/sudo.8.gz
$ whereis source
source: /usr/share/man/man1/source.1.gzHowever, when I attempt to execute tcl as-
sudo tclsh /opt/test.tclI get the expected output-
hello, worldAm I missing something here?
1 Answer
source is a shell builtin. Your shell cannot find source for the same reason it can't find cd when you're using sudo - it is not a command. You can use the shell builtin type to check this yourself.
source executes the content of a file you specify in your current shell. That should be fine as long as you don't need an interactive shell, and that your current shell is tclsh. Read here for more information.
sudo tclsh /opt/test.tclwill work, but it will run in a non-interactive shell.
If you do need to source the script for some reason, decide whether you need to do special permissions or not. If you must, you can su to root and source the script from there.
Also, the output you got for $ whereis source
source: /usr/share/man/man1/source.1.gzseems to be a man page. So that probably wasn't going to be much use!