Jolly Roger <
jolly...@pobox.com> writes:
> The question is what exactly is happening here:
>
> bin/RandiGen
> -bash: bin/RandiGen: /bin/sh: bad interpreter: Operation not permitted
>
> This seems like a good shebang:
>
> iMac:~ wgroleau$ od -xc bin/RandiGen | head
> 0000000 2123 622f 6e69 732f 0a68
> # ! / b i n / s h \n
>
> So what would cause /bin/sh to run fine when executed explicitly on the
> command line, but not from a script shebang?
Based on the different errors when running interactively vs. internally
through the script, it looks likely that it's a .profile issue. /bin/sh
on the Mac is actually a copy of bash, and bash, when invoked as sh,
behaves a little differently from when it's run as bash directly.
In particular, check not just the contents of any ~/.profile, ~/.bashrc,
~/bash_profile, ~/.bash_login files, but additionally look for
system-wide startup files such as /etc/profile
That said, the /bin/sh bad interpreter is a weird error - if
a shebang (hashbang, whatever) line has a non-existent interpreter,
the error from trying to execute that file usually tells us
the name and path to the non-existent intepreter and, clearly, /bin/sh
exists.
For example, I wrote a script called "test2shebang" and the
entire contents of that file is the one line
#!/path/to/nowhere
I set test2shebang to be executable and ran it (my $SHELL
being /bin/bash) and got the expected:
bash: ./test2shebang: /path/to/nowhere: bad interpreter: No such file or
directory
But *not* an "Operation not permitted". That sounds like it's finding
/bin/sh just fine, but that it doesn't have permissions to read or
execute the file in question. Very strange.
Anyway, as I said, even if you have no ~/.?* files in your home
directory, make sure you check /etc/profile which is, in fact,
present by default on at least a Snow Leopard installation, to
see if it's trying to run something else.
Note that it, too, may run other scripts and .rc files, such as
/etc/bashrc
--
Plain Bread alone for e-mail, thanks. The rest gets trashed.