Re: home dir executable (!/bin/sh, chmod+x) shell scripts won't run without "sh <script>"

On Jan 7, 2008, at 9:52 AM, Steve Franks wrote:

I keep reading about making sh scripts executable with #!/bin/sh on
the first line and chmod to executable. That works with all my system
scripts (rc, etc.) or my system would be DOA, no doubt. When I do it
in my home folder, however, running <script> gives "command not
found". I've only read about 5 sites telling you how to make shell
scripts executable, they all say the same thing, and they all don't
work. How did I get to be so special?



This is a sort of 'don't shoot yourself in the foot' design. You cannot run a script or binary simply by name if you're cwd is the directory that contains that script or binary. IIRC, you can't cd / usr/bin and run anything in /usr/bin without explicitly calling that file with the ./ telling the system THIS ONE.

The reason for this is to prevent someone, a shady fellow, from putting a shell script in, say, a shared directory called ls, and making it executable, and have some similarly shady code such as:

exit 0;

Or something like that. ;)

Eric F Crist
Secure Computing Networks

freebsd-questions@xxxxxxxxxxx mailing list
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"