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.

2
  • For me, the first example works like yours and the second works like you intended (Mac OS X Mountain Lion, bash 3.2.48(1)) Commented Dec 8, 2012 at 20:38
  • Oh great. It is OS dependent? I'm using CentOS release 5.2 Commented Dec 8, 2012 at 20:44

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.