X-Recipient: archive-cygwin@delorie.com
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 639FE3857C5E
Authentication-Results: sourceware.org; dmarc=none (p=none dis=none)
 header.from=SystematicSw.ab.ca
Authentication-Results: sourceware.org;
 spf=none smtp.mailfrom=brian.inglis@systematicsw.ab.ca
X-Authority-Analysis: v=2.4 cv=P9aEOgMu c=1 sm=1 tr=0 ts=5f9dbf30
 a=kiZT5GMN3KAWqtYcXc+/4Q==:117 a=kiZT5GMN3KAWqtYcXc+/4Q==:17
 a=IkcTkHD0fZMA:10 a=uYT-Tk0qkVT609LjNaIA:9 a=QEXdDO2ut3YA:10
Subject: Re: How to ensure that /bin takes priority over System32 with "bash
 -c"?
To: cygwin@cygwin.com
References: <CAC+X2=+bkYcN9Qv1kUNom3q3Ljek=Xw888QW-ueYipX3WrKphg@mail.gmail.com>
 <CA+kUOamhcRTR8Fij52_pD4G7=vq_c2mzGj1U9N_q2ntp5kUKXQ@mail.gmail.com>
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
Autocrypt: addr=Brian.Inglis@SystematicSw.ab.ca; prefer-encrypt=mutual;
 keydata=
 mDMEXopx8xYJKwYBBAHaRw8BAQdAnCK0qv/xwUCCZQoA9BHRYpstERrspfT0NkUWQVuoePa0
 LkJyaWFuIEluZ2xpcyA8QnJpYW4uSW5nbGlzQFN5c3RlbWF0aWNTdy5hYi5jYT6IlgQTFggA
 PhYhBMM5/lbU970GBS2bZB62lxu92I8YBQJeinHzAhsDBQkJZgGABQsJCAcCBhUKCQgLAgQW
 AgMBAh4BAheAAAoJEB62lxu92I8Y0ioBAI8xrggNxziAVmr+Xm6nnyjoujMqWcq3oEhlYGAO
 WacZAQDFtdDx2koSVSoOmfaOyRTbIWSf9/Cjai29060fsmdsDLg4BF6KcfMSCisGAQQBl1UB
 BQEBB0Awv8kHI2PaEgViDqzbnoe8B9KMHoBZLS92HdC7ZPh8HQMBCAeIfgQYFggAJhYhBMM5
 /lbU970GBS2bZB62lxu92I8YBQJeinHzAhsMBQkJZgGAAAoJEB62lxu92I8YZwUBAJw/74rF
 IyaSsGI7ewCdCy88Lce/kdwX7zGwid+f8NZ3AQC/ezTFFi5obXnyMxZJN464nPXiggtT9gN5
 RSyTY8X+AQ==
Organization: Systematic Software
Message-ID: <6f509ff1-af03-b166-be86-f457914fd33f@SystematicSw.ab.ca>
Date: Sat, 31 Oct 2020 13:46:55 -0600
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101
 Thunderbird/68.12.1
MIME-Version: 1.0
In-Reply-To: <CA+kUOamhcRTR8Fij52_pD4G7=vq_c2mzGj1U9N_q2ntp5kUKXQ@mail.gmail.com>
Content-Language: en-CA
X-CMAE-Envelope: MS4xfCGd2xbTy8Jmx5v/dyYIDwO6R6U7NGXHudGk6nkuCycw8ndLB4yvf+LtrrYQX/KsQDBH9ZNyiZn1E2t3jcpAoeeF2K3J8drmq26mGd9ve8mRao4oI7Me
 nZGZ8Wj62WF2lE3wy/3KkosILC4FxAiwRwq59HeV1Er89N8MYf/m+jFAO/vXLYZ5nXksg0fS5EKMzBPyBZ/Z5uoM2a+peIGagtQ=
X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS,
 KAM_LAZY_DOMAIN_SECURITY, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4,
 RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE,
 TXREP autolearn=ham autolearn_force=no version=3.4.2
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
Reply-To: cygwin@cygwin.com
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces@cygwin.com
Sender: "Cygwin" <cygwin-bounces@cygwin.com>

On 2020-10-31 08:21, Adam Dinwoodie wrote:
> 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.

Remember 'where' is like the Windows version of Cygwin which or whereis, so you
see only the Windows view of the current PATH:

$ where where /t
     33280   2019-03-18      22:46:08  C:\Windows\System32\where.exe

I export to the env or prefix any such commands, for example, commands that
start another mintty window in some arch, WSL distro, etc. or run a script in
one of those, with BASH_ENV=$HOME/.bash_env:

$ head ~/.bash_env
#|/bin/bash
# ~/.bash_env - set up bash environment for non-login non-interactive shells
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:$PATH"

-- 
-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]
--
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
