I'm trying to implement, in shell, a script interpreter that I can use in a shebang line. For example, here is my interpreter and a test script using that interpreter:
-----
$ cat interp
#! /usr/bin/env bash
printf "interp called with args: %s\n" "$*"
-----
$ cat test
#! ./interp
printf "test script!\n"
When I run ./test on a Linux system, interp is called with the arguments that I expect:
$ ./test -a
interp called with args: ./test -a
But when I do the same on Mac OS X 10.8.4, I get the following result:
$ ./test -a
test script!
The contents of the test script are being executed by bash, rather than the interp script being executed with the test file as the first argument.
Am I doing this correctly and such a thing simply won't work on Mac OS X? Or is there a better way to accomplish this?
/usr/bin/env(a binary executable) and requests it to run your script.