Date: Thu, 2 Mar 2023 11:52:15 -0600 From: "A. Wilcox" <awilfox@...lielinux.org> To: musl@...ts.openwall.com Subject: Re: Off topic question about shebang and exec() On Mar 2, 2023, at 10:32 AM, Markus Wichmann <nullplan@....net> wrote: > > On Thu, Mar 02, 2023 at 04:15:38PM +0200, Paul Schutte wrote: >> Hi all >> >> I apologize for abusing the knowledge of the people on this list, but I >> know they will know the answer. Google does not provide a usable answer. >> >> I am busy writing a toy language and I would like it to be used as both a >> compiler and "interpreter" >> >> I would like it to compile the source and then run the resulting binary >> when the source file is called via the shebang and it should just do a >> normal compile when called with "compile code.src" >> >> argv contains the path to the compiler in both cases, which makes sense. >> >> Is there any way to determine which method was used to call the compiler? >> >> Kind Regards >> Paul > > Not to my knowledge. I would also consider it poor design to use a trick > like that. The normal assumption is that a shebang and just running the > command from command line are equivalent. > > Normal solution here is to have a command line switch to select one > behavior or the other. That switch can be added to the shebang or the > command line, whatever you choose. > > Ciao, > Markus An even better solution is hinted in OP's problem description: argv. Have two entry points, like a multi call binary, based on that. You could use a softlink or hardlink named `lang` to `langc`. Best, -A.
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.