Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.tcl

I got the output-

sudo: source: command not found

But 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.gz

However, when I attempt to execute tcl as-

sudo tclsh /opt/test.tcl

I get the expected output-

hello, world

Am I missing something here?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.tcl

will 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.gz

seems to be a man page. So that probably wasn't going to be much use!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.