From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id EE1333861038 for ; Sat, 31 Oct 2020 14:21:40 +0000 (GMT) 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@dinwoodie.org Received: by mail-ot1-x32c.google.com with SMTP id f37so8291204otf.12 for ; Sat, 31 Oct 2020 07:21:40 -0700 (PDT) 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: In-Reply-To: From: Adam Dinwoodie Date: Sat, 31 Oct 2020 14:21:05 +0000 Message-ID: Subject: Re: How to ensure that /bin takes priority over System32 with "bash -c"? To: "Cygwin (cygwin@cygwin.com)" Content-Type: text/plain; charset="UTF-8" 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@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2020 14:21:44 -0000 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