On Fri, 4 May 2001, Oliver Maunder wrote:
I'm fairly new to Linux, and I've come across a strange problem. Sometimes, when I try to run a script as root, bash says it can't find the command.
Here's an example:
root@linux:/usr/local/Freenet > ls -l total 720 -rw-r--r-- 1 root root 18007 Apr 27 22:50 COPYING -rw-r--r-- 1 root root 1363 Apr 27 22:50 Changelog -rw-r--r-- 1 root root 7209 Apr 27 22:50 README -rw-r--r-- 1 root root 668190 Apr 27 22:50 freenet.jar -rwxr-xr-x 1 root root 513 Apr 27 22:50 freenet_config -rwxr-xr-x 1 root root 525 Apr 27 22:50 freenet_insert -rwxr-xr-x 1 root root 528 Apr 27 22:50 freenet_request -rwxr-xr-x 1 root root 505 Apr 27 22:50 freenet_server -rw-r--r-- 1 root root 7365 Apr 27 22:50 mime.types -rw-r--r-- 1 root root 5749 Apr 27 22:50 sample.freenetrc root@linux:/usr/local/Freenet > freenet_server bash: freenet_server: command not found
Root owns the file, and it's executable, so what's the problem? I can run this script from my user account. Is bash trying to stop me being stupid and running potentially dangerous scripts as root?
Well, kind of. The root user's PATH environment variable does not contain the current directory for security reasons (Imagine someone places a nasty script named "ls" in a publicly writable directory like /tmp, that executes "rm -rf /" when called - this is fatal, if you have root permissions.). If you want to execute a command or script in the local directory, call it like this "./<script>", e.g. "./freenet_server". That should be it. "./" means "the current directory". LenZ -- ------------------------------------------------------------------ Lenz Grimmer SuSE GmbH mailto:grimmer@suse.de Schanzaeckerstr. 10 http://www.suse.de/~grimmer/ 90443 Nuernberg, Germany The only roses without thorns are love and friendship.