mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "A. Wilcox" <awilfox@adelielinux.org>
To: musl@lists.openwall.com
Subject: Re: [musl] Off topic question about shebang and exec()
Date: Thu, 2 Mar 2023 11:52:15 -0600	[thread overview]
Message-ID: <8CC35F99-22CF-42A8-B326-987171DEDF06@adelielinux.org> (raw)
In-Reply-To: <20230302163222.GI1903@voyager>

On Mar 2, 2023, at 10:32 AM, Markus Wichmann <nullplan@gmx.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[0] 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[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.

  reply	other threads:[~2023-03-02 17:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 14:15 Paul Schutte
2023-03-02 16:32 ` Markus Wichmann
2023-03-02 17:52   ` A. Wilcox [this message]
2023-03-03 11:17     ` [musl] " Valery Ushakov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8CC35F99-22CF-42A8-B326-987171DEDF06@adelielinux.org \
    --to=awilfox@adelielinux.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).