Multiple arguments on a #! line

Scott Paul Robertson spr at
Sat Jan 6 01:00:26 MST 2007

On Fri, Jan 05, 2007 at 11:22:46PM -0700, Byron Clark wrote:
> 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
> argument?  

Most Unix systems[1] will only parse a single option, in a very
unintelligent way: the option passed is the first non-whitespace
character until the end of the line.

Because of this a #! will lump all the options as one. Try leaving some
trailing whitespace, it'll preserve it as well. This is more tradition
than anything, apparently POSIX doesn't say anything about handling #!
lines. Linux goes the traditional route.

Interesting side note, on OS X the kernel handles multiple arguments:
$ ./
[0] /Users/spr/test
[1] -u
[2] -tt
[3] ./

That got me mad because I could do what you're wanting to do on my OS X
box, but in Linux it kept messing up.


[1] From Classic Shell Scripting, O'Reilly

Scott Paul Robertson
GnuPG FingerPrint: 09ab 64b5 edc0 903e 93ce edb9 3bcc f8fb dc5d 7601
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : 

More information about the PLUG mailing list