public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Adam Dinwoodie <adam@dinwoodie.org>
To: "Cygwin (cygwin@cygwin.com)" <cygwin@cygwin.com>
Subject: Re: How to ensure that /bin takes priority over System32 with "bash -c"?
Date: Sat, 31 Oct 2020 14:21:05 +0000	[thread overview]
Message-ID: <CA+kUOamhcRTR8Fij52_pD4G7=vq_c2mzGj1U9N_q2ntp5kUKXQ@mail.gmail.com> (raw)
In-Reply-To: <CAC+X2=+bkYcN9Qv1kUNom3q3Ljek=Xw888QW-ueYipX3WrKphg@mail.gmail.com>

On Sat, 31 Oct 2020 at 13:16, Matt D. via Cygwin wrote:
> I can't always know what binaries exist in C:\Windows\System32 when
> writing my scripts. Am I supposed to always launch scripts as "bash
> --login -i -c"? I don't want or need to have bash run all of its login
> scripts unnecessarily.
>
> How can I run my bash scripts without invoking it as a login shell and
> ensure that /bin has the environment priority over System32 binaries?

Currently, your commands are doing exactly what you tell them: you're
not doing anything to override the PATH from Windows, so they're using
the PATH from Windows.

On a full Linux system, this is generally not an issue, because you
won't have any processes trying to run as children of processes with
Windows PATH variables. For most Cygwin users, this isn't a problem
because they either (a) just accept the performance impact of running
things with a login shell, or (b) (which I suspect is more likely) run
most things from within a login shell or some other environment like
cron that knows how to set the appropriate variables up.

If none of the above are options for you, you'll need to find some way
to set the environment variables you need. This might just be starting
your Bash commands with `export PATH=/bin:/sbin:$PATH`. Alternatively
you could look at using the BASH_ENV environment variable; if you
create, say, /etc/bashenv in Cygwin containing `export
PATH=/bin:/sbin:$PATH` and any other commands you need, and set
BASH_ENV=/etc/bashenv as a Windows system environment variable, I
believe Bash should read that when started up in the way you're using
it, and assuming you don't have any other non-Cygwin Bash programs on
your system (e.g. from Git for Windows), I doubt it'd affect anything
else.

HTH

Adam

  reply	other threads:[~2020-10-31 14:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-31 13:16 Matt D.
2020-10-31 14:21 ` Adam Dinwoodie [this message]
2020-10-31 19:46   ` Brian Inglis

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='CA+kUOamhcRTR8Fij52_pD4G7=vq_c2mzGj1U9N_q2ntp5kUKXQ@mail.gmail.com' \
    --to=adam@dinwoodie.org \
    --cc=cygwin@cygwin.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).