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

Josh Carroll josh.carroll at gmail.com
Mon Jan 7 08:27:30 PST 2008


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

That typically indicates the path you've specified in the sh-bang does
not exist. Another common problem there is if the shell script was
written out in DOS format.

If you're certain the first line looks proper, and that the path
exists (/bin/sh most certainly should), try:

perl -p -i -e 's/\r\n/\n/' foo.sh

Then see if it works.

> scripts executable, they all say the same thing, and they all don't
> work.  How did I get to be so special?

It's possible the partition /home is mounted on is mounted with
noexec, but in that case, I'd expect you'd get a "permission denied"
message, rather than "command not found".

Josh


More information about the freebsd-questions mailing list