delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2020/10/31/10:22:39

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EE1333861038
Authentication-Results: sourceware.org;
dmarc=none (p=none dis=none) header.from=dinwoodie.org
Authentication-Results: sourceware.org;
spf=pass smtp.mailfrom=adam AT dinwoodie DOT org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=dinwoodie.org; s=google;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=Hy6p6T4Wj9fD+lytmgXN9wMwfSm7k/t2np0GvrofQEU=;
b=e4slcM78coMalTnFtSo3oswvOCS4PadoFbCNGWLeR0o8nYD4Ww8r0E47VkOzRgeAKk
bETTh3jVjPTlw5DNnidWJPNNUioJzxjRQMrO5UOMZhvWymUgfj2gpK07+I5Gacx8Vjas
FqYYFxrJKMcl9EGo7Rq2p2MCZjBF/drEqM2+A=
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=Hy6p6T4Wj9fD+lytmgXN9wMwfSm7k/t2np0GvrofQEU=;
b=Drvx1ChAmPLhQRN4M9sMP8HLKHLOjDcxNVnuUpFRazBwV570hWC6+BdQfMM5eO7PwI
G6M7yWRLSlivgL4Z1Z/mzLE3UIXK6EZNWYrFuv1yawxpTbqNwtEozPgD2TfPyYuKk8Qp
CQHeMpR5Q3V2z1fVGOAuix4wwOUL6DPnxkXrWEs2vDu0lldAHcA85aS6X3iJ9CshPvUP
pVdfHhSpaqOQ4S8sLeAdXHx7BygxLc+arhDF1slnF4DAyzF1loBgHEzjJ3ifE40FgaC+
AkCOjfNiTIsBWyzmwAl8Cbt2Qu3u5uoxoAmGrMZpGSN/Vd7mwJvqgF+0kkN1zYNhGNnG
I8/A==
X-Gm-Message-State: AOAM5314aMdJR2vASOdIuBQ2ZtMSoxmV0hyZ6yBIX7GGl1pSaz0JqT7F
tmNrBqOjLzFZK9S1uEMUUNMhZ3licZFRpN8Mxp1DM3mU8GI=
X-Google-Smtp-Source: ABdhPJzGIwdFI5/30ieSBMdubK595PFI2tA3D31WcK56+k+Yd/jCIqri5nq7ROSfcWpiO2MtxqugnCJv22SfHauUQfw=
X-Received: by 2002:a9d:7388:: with SMTP id j8mr5609997otk.297.1604154100025;
Sat, 31 Oct 2020 07:21:40 -0700 (PDT)
MIME-Version: 1.0
References: <CAC+X2=+bkYcN9Qv1kUNom3q3Ljek=Xw888QW-ueYipX3WrKphg AT mail DOT gmail DOT com>
In-Reply-To: <CAC+X2=+bkYcN9Qv1kUNom3q3Ljek=Xw888QW-ueYipX3WrKphg@mail.gmail.com>
From: Adam Dinwoodie <adam AT dinwoodie DOT org>
Date: Sat, 31 Oct 2020 14:21:05 +0000
Message-ID: <CA+kUOamhcRTR8Fij52_pD4G7=vq_c2mzGj1U9N_q2ntp5kUKXQ@mail.gmail.com>
Subject: Re: How to ensure that /bin takes priority over System32 with "bash
-c"?
To: "Cygwin (cygwin AT cygwin DOT com)" <cygwin AT cygwin DOT com>
X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, DKIM_SIGNED,
DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,
SPF_PASS, 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 AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
Sender: "Cygwin" <cygwin-bounces AT cygwin DOT 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
--
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019