Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Jan 2008 10:01:43 -0600
From:      Eric Crist <mnslinky@gmail.com>
To:        stevefranks@ieee.org
Cc:        User Questions <freebsd-questions@freebsd.org>
Subject:   Re: home dir executable (!/bin/sh, chmod+x) shell scripts won't run without "sh <script>"
Message-ID:  <5D884B59-3CEF-4F81-B35D-4E54F5D6301C@gmail.com>
In-Reply-To: <539c60b90801070752l3d0e571cq8f7b1b519e1e808c@mail.gmail.com>
References:  <539c60b90801070752l3d0e571cq8f7b1b519e1e808c@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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?
>
> Steve

Steve,

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:

#!/bin/sh
take_over_world(now);
exit 0;

Or something like that. ;)

HTH
-----
Eric F Crist
Secure Computing Networks





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5D884B59-3CEF-4F81-B35D-4E54F5D6301C>