4

Possible Duplicate:
how to use multiple arguments with a shebang (i.e. #!)?

How can I make a #! statement accept a param with arguments? It seems to be lumping them all together as one param instead of splitting on space as usual.

Take this contrived example:

$ cat /tmp/echo
#!/bin/echo -n
$ /tmp/echo
/tmp/echo$

works great and outputs the filename without a new line at the end. But this one:

$ cat /tmp/echo
#!/bin/echo -n hi
$ /tmp/echo
-n hi /tmp/echo
$

kills the -n arg.

One hack I can do is make another shell script that just execs the first script I want with the params I want, but I'd rather not add extra dependancies if I don't need them.

Community
  • 1
  • 1
Paul Tarjan
  • 48,968
  • 59
  • 172
  • 213

1 Answers1

2

There apparently isn't a POSIX standard for this, but many (possibly most) *nix systems only allow you to send one argument to the program invoked in the shabang. So using #!/bin/echo -n hi is effectively the same as running /bin/echo "-n hi" /path/to/script.

See this SO answer for a more thorough explanation.

Community
  • 1
  • 1
Tim Pote
  • 27,191
  • 6
  • 63
  • 65