* Shebang - why are parameters not splitted on whitespace? @ 2008-12-03 15:14 Geralt 2008-12-03 15:56 ` Américo Wang 0 siblings, 1 reply; 7+ messages in thread From: Geralt @ 2008-12-03 15:14 UTC (permalink / raw) To: linux-kernel Hi, I've just noticed, that it's not possible to use more than one parameter in a shebang on linux, because everything following the executable path in the shebang is treated as one parameter, so for example #!/bin/awk --re-interval -f in a script called "test.awk" results in a call likes this: /bin/awk "--re-interval -f" ./test.awk when running it with "./test.awk". Is there any reason why the parameters are not split before passing them on to the program? I mean we're talking here about linux where every program starts somewhere with int main( int argc, char* argv[]), i.e. the arguments are given piecewise, not in one big string (as it is the case for win32 applications), so I was very surprised at first why my snipped from above did not work and I suppose a lot of people would expect it to behave in the natural way (= splitting the arguments). Geralt. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shebang - why are parameters not splitted on whitespace? 2008-12-03 15:14 Shebang - why are parameters not splitted on whitespace? Geralt @ 2008-12-03 15:56 ` Américo Wang [not found] ` <fbdd0e50812030929q65d2e805y49094dd67209be7e@mail.gmail.com> 0 siblings, 1 reply; 7+ messages in thread From: Américo Wang @ 2008-12-03 15:56 UTC (permalink / raw) To: Geralt; +Cc: linux-kernel On Wed, Dec 3, 2008 at 3:14 PM, Geralt <usr.gentoo@googlemail.com> wrote: > Hi, > > I've just noticed, that it's not possible to use more than one > parameter in a shebang on linux, because everything following the > executable path in the shebang is treated as one parameter, so for > example > #!/bin/awk --re-interval -f > in a script called "test.awk" results in a call likes this: > /bin/awk "--re-interval -f" ./test.awk > when running it with "./test.awk". > > Is there any reason why the parameters are not split before passing > them on to the program? Hello, I think this behavior is different on different platforms, you can find some clues in man page of execve(2): The semantics of the optional-arg argument of an interpreter script vary across implementations. On Linux, the entire string following the interpreter name is passed as a single argument to the interpreter, and this string can include white space. However, behavior differs on some other systems. Some systems use the first white space to terminate optional-arg. On some systems, an interpreter script can have multiple arguments, and white spaces in optional-arg are used to delimit the arguments It seems that POSIX doesn't specify this. Thanks. ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <fbdd0e50812030929q65d2e805y49094dd67209be7e@mail.gmail.com>]
* Re: Shebang - why are parameters not splitted on whitespace? [not found] ` <fbdd0e50812030929q65d2e805y49094dd67209be7e@mail.gmail.com> @ 2008-12-03 17:29 ` Geralt 2008-12-06 1:04 ` Américo Wang 0 siblings, 1 reply; 7+ messages in thread From: Geralt @ 2008-12-03 17:29 UTC (permalink / raw) To: linux-kernel On Wed, Dec 3, 2008 at 4:56 PM, Américo Wang <xiyou.wangcong@gmail.com> wrote: > On Wed, Dec 3, 2008 at 3:14 PM, Geralt <usr.gentoo@googlemail.com> wrote: >> Hi, >> >> I've just noticed, that it's not possible to use more than one >> parameter in a shebang on linux, because everything following the >> executable path in the shebang is treated as one parameter, so for >> example >> #!/bin/awk --re-interval -f >> in a script called "test.awk" results in a call likes this: >> /bin/awk "--re-interval -f" ./test.awk >> when running it with "./test.awk". >> >> Is there any reason why the parameters are not split before passing >> them on to the program? > > > Hello, > > I think this behavior is different on different platforms, you can > find some clues > in man page of execve(2): > > The semantics of the optional-arg argument of an interpreter script > vary across implementations. On Linux, the entire string following the > interpreter name is passed as a single argument to the interpreter, and > this string can include white space. However, behavior differs on some > other systems. Some systems use the first white space to terminate > optional-arg. On some systems, an interpreter script can have multiple > arguments, and white spaces in optional-arg are used to delimit the > arguments > > It seems that POSIX doesn't specify this. > > Thanks. > Hello, I should have anticipated this objection :-). I'm aware that this is not consistent among Unix operating systems (you can find more about it here [1]), but I was specifically refering to linux in this case and why it handles the shebang arguments as one big string and not as single arguments for the application. Geralt. [1] http://www.in-ulm.de/~mascheck/various/shebang/ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shebang - why are parameters not splitted on whitespace? 2008-12-03 17:29 ` Geralt @ 2008-12-06 1:04 ` Américo Wang 2008-12-06 5:41 ` Valdis.Kletnieks 0 siblings, 1 reply; 7+ messages in thread From: Américo Wang @ 2008-12-06 1:04 UTC (permalink / raw) To: Geralt; +Cc: linux-kernel On Wed, Dec 3, 2008 at 5:29 PM, Geralt <usr.gentoo@googlemail.com> wrote: > Hello, > > I should have anticipated this objection :-). I'm aware that this is > not consistent among Unix operating systems (you can find more about > it here [1]), but I was specifically refering to linux in this case > and why it handles the shebang arguments as one big string and not as > single arguments for the application. I can't think out any strong reasons, maybe only becasue Linux developers prefer that approach. Thanks. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shebang - why are parameters not splitted on whitespace? 2008-12-06 1:04 ` Américo Wang @ 2008-12-06 5:41 ` Valdis.Kletnieks 2008-12-06 12:02 ` Geralt 0 siblings, 1 reply; 7+ messages in thread From: Valdis.Kletnieks @ 2008-12-06 5:41 UTC (permalink / raw) To: Américo Wang; +Cc: Geralt, linux-kernel [-- Attachment #1: Type: text/plain, Size: 690 bytes --] On Sat, 06 Dec 2008 01:04:52 GMT, Américo Wang said: > On Wed, Dec 3, 2008 at 5:29 PM, Geralt <usr.gentoo@googlemail.com> wrote: > > Hello, > > > > I should have anticipated this objection :-). I'm aware that this is > > not consistent among Unix operating systems (you can find more about > > it here [1]), but I was specifically refering to linux in this case > > and why it handles the shebang arguments as one big string and not as > > single arguments for the application. > > I can't think out any strong reasons, maybe only becasue Linux developers > prefer that approach. And of course, "whitespace" is a somewhat fungible concept. 'man bash' and read about $IFS. [-- Attachment #2: Type: application/pgp-signature, Size: 226 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shebang - why are parameters not splitted on whitespace? 2008-12-06 5:41 ` Valdis.Kletnieks @ 2008-12-06 12:02 ` Geralt 2008-12-06 21:14 ` Aaron Cohen 0 siblings, 1 reply; 7+ messages in thread From: Geralt @ 2008-12-06 12:02 UTC (permalink / raw) To: Valdis.Kletnieks, Américo Wang, linux-kernel On Sat, Dec 6, 2008 at 6:41 AM, <Valdis.Kletnieks@vt.edu> wrote: > On Sat, 06 Dec 2008 01:04:52 GMT, Américo Wang said: >> On Wed, Dec 3, 2008 at 5:29 PM, Geralt <usr.gentoo@googlemail.com> wrote: >> > Hello, >> > >> > I should have anticipated this objection :-). I'm aware that this is >> > not consistent among Unix operating systems (you can find more about >> > it here [1]), but I was specifically refering to linux in this case >> > and why it handles the shebang arguments as one big string and not as >> > single arguments for the application. >> >> I can't think out any strong reasons, maybe only becasue Linux developers >> prefer that approach. > > And of course, "whitespace" is a somewhat fungible concept. 'man bash' > and read about $IFS. > So you're saying that you can't do that because you don't know where to split the parameters, right? But would it be that bad to state a rule what "whitespace" is in the shebang line? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shebang - why are parameters not splitted on whitespace? 2008-12-06 12:02 ` Geralt @ 2008-12-06 21:14 ` Aaron Cohen 0 siblings, 0 replies; 7+ messages in thread From: Aaron Cohen @ 2008-12-06 21:14 UTC (permalink / raw) To: Geralt; +Cc: Valdis.Kletnieks, Américo Wang, linux-kernel You should read this thread: http://unix.derkeiler.com/Mailing-Lists/FreeBSD/arch/2005-02/0039.html The shebang processing needs to somehow magically split up the first line into the file into "some number of arguments for the interpreter" "some number of arguments for the script being run", and "the script being run." The first two are the big difficulty, how should the kernel know which arguments are meant for the interpreter and which are meant for the script? In the article I referenced, current Linux behavior seems to conform to at least the majority of other OSes do, and I believe freeBSD actually moved from trying to split the arguments up into something similar (though I couldn't swear to it). --Aaron On Sat, Dec 6, 2008 at 4:02 AM, Geralt <usr.gentoo@googlemail.com> wrote: > On Sat, Dec 6, 2008 at 6:41 AM, <Valdis.Kletnieks@vt.edu> wrote: >> On Sat, 06 Dec 2008 01:04:52 GMT, Américo Wang said: >>> On Wed, Dec 3, 2008 at 5:29 PM, Geralt <usr.gentoo@googlemail.com> wrote: >>> > Hello, >>> > >>> > I should have anticipated this objection :-). I'm aware that this is >>> > not consistent among Unix operating systems (you can find more about >>> > it here [1]), but I was specifically refering to linux in this case >>> > and why it handles the shebang arguments as one big string and not as >>> > single arguments for the application. >>> >>> I can't think out any strong reasons, maybe only becasue Linux developers >>> prefer that approach. >> >> And of course, "whitespace" is a somewhat fungible concept. 'man bash' >> and read about $IFS. >> > So you're saying that you can't do that because you don't know where > to split the parameters, right? But would it be that bad to state a > rule what "whitespace" is in the shebang line? > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-12-06 21:15 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-03 15:14 Shebang - why are parameters not splitted on whitespace? Geralt
2008-12-03 15:56 ` Américo Wang
[not found] ` <fbdd0e50812030929q65d2e805y49094dd67209be7e@mail.gmail.com>
2008-12-03 17:29 ` Geralt
2008-12-06 1:04 ` Américo Wang
2008-12-06 5:41 ` Valdis.Kletnieks
2008-12-06 12:02 ` Geralt
2008-12-06 21:14 ` Aaron Cohen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®