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"

Relevant Pages

  • Re: pop-forum Re: poplog-dev A look at Poplog on the Macintosh
    ... with the poplink command. ... When trying to make pglink produce a 'sh' rather than a 'csh' shell ... script for linking and when trying to make it put unexpanded environment ... using the shell script pglibr, ...
  • Files appear to be cross linked
    ... script requires a number of standard environment variables to be set ... so it calls a second shell script to set these at the session level, ... control should return to the first shell script, ... that the script executes to the last line prior to the displaying of ...
  • Re: [PHP] Catch STDERR
    ... into your PHP script? ... Or do you just need STDOUT in one variable, and STDERR in another, ... Another option is to try to write a .sh shell script to get what you ...
  • Re: Converting large bash script to TCL
    ... I know that TCL and shell scripting share a lot of similarities. ... The shell script ... Determine what it (the script) is supposed to do ... echo "WOULD YOU LIKE TO INSTALL NAC DRIVER ...
  • Re: basic questions
    ... Setting a script that runs at 3:00 ... Set chron to run that shell script. ... Debug the GUI application with the REPL. ... You start up the Web browser, then browse the Web, visit a hundred ...