Multiple arguments on a #! line

Byron Clark byron at
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>

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
[0] /tmp/test
[1] -u
[2] -tt

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 and made it executable.

#!/tmp/test -u -tt

Here's what happens when I run

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

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

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 : 

More information about the PLUG mailing list