From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 15963 invoked from network); 2 Mar 2023 17:52:40 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 2 Mar 2023 17:52:40 -0000 Received: (qmail 21660 invoked by uid 550); 2 Mar 2023 17:52:36 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 21623 invoked from network); 2 Mar 2023 17:52:35 -0000 From: "A. Wilcox" Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Date: Thu, 2 Mar 2023 11:52:15 -0600 References: <20230302163222.GI1903@voyager> To: musl@lists.openwall.com In-Reply-To: <20230302163222.GI1903@voyager> Message-Id: <8CC35F99-22CF-42A8-B326-987171DEDF06@adelielinux.org> X-Mailer: Apple Mail (2.3696.120.41.1.1) Subject: Re: [musl] Off topic question about shebang and exec() On Mar 2, 2023, at 10:32 AM, Markus Wichmann wrote: >=20 > On Thu, Mar 02, 2023 at 04:15:38PM +0200, Paul Schutte wrote: >> Hi all >>=20 >> 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. >>=20 >> I am busy writing a toy language and I would like it to be used as = both a >> compiler and "interpreter" >>=20 >> 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" >>=20 >> argv[0] contains the path to the compiler in both cases, which makes = sense. >>=20 >> Is there any way to determine which method was used to call the = compiler? >>=20 >> Kind Regards >> Paul >=20 > 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. >=20 > 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. >=20 > Ciao, > Markus An even better solution is hinted in OP's problem description: argv[0]. 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.=