Multiple arguments on a #! line

Byron Clark byron at theclarkfamily.name
Fri Jan 5 23:22:46 MST 2007


I'm hoping someone can explain why #! lines seem to act strangely with
more than one argument to the provided executable.  Here's a little
example to show what I mean.

I wrote the following simple C program and compiled it to /tmp/test. 

#include <stdio.h>

int
main(int argc, char **argv)
{
    int i;

    /* print out the args */
    for (i = 0; i < argc; ++i)
        fprintf(stderr, "[%d] %s\n", i, argv[i]);

    return 0;
}

Nothing too complicated there, it should just print the arguments it
receives on the command line, in fact, here is an example run:

$ /tmp/test -u -tt foo.sh
[0] /tmp/test
[1] -u
[2] -tt
[3] foo.sh

Now, I should be able to use this in a #! line to "run" a script, so I
wrote the following script that does absolutely nothing and called it
test.sh and made it executable.

#!/tmp/test -u -tt

Here's what happens when I run test.sh:

$ ./test.sh
[0] /tmp/test
[1] -u -tt
[2] ./test.sh

So, _why_ are the command line arguments being combined into a single
argument?  

ps - The real background for this is that I wanted to pass two arguments
to python on the #! line and was getting errors about invalid options.
ruby shows the same kind of behavior with more than one option.  Just to
fan the usual plug flames, perl does some kind of magic and handles this
case successfully.

--
Byron Clark
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://plug.org/pipermail/plug/attachments/20070105/8c68ce8e/attachment.bin 


More information about the PLUG mailing list