On 2025-08-04 17:30, Matthew Sheets via Cygwin-apps wrote:
Are there two different versions of Cygwin.bat that Cygwin Setup could create 
depending on the context in which Cygwin Setup is executed?

If Cygwin setup is being used to create a new installation, the installed 
Cygwin.bat is fairly path independent:
@echo off
setlocal enableextensions
set TERM=
cd /d "%~dp0bin" && .\bash --login -i


However, if Cygwin setup is being executed for an already-existing installation 
and restores a deleted Cygwin.bat, that restored Cygwin.bat contains hard-coded 
paths:
@echo off
C:
chdir C:\Portable\Cygwin\arch-x86_64\bin
bash --login -i

I still had one of the latter installed from 2013!

If you look at one of the base packages:

$ cygcheck -l base-files
/etc/defaults/Cygwin.bat
...
/etc/postinstall/base-files-profile.sh
/etc/preremove/base-files-manifest.lst
/etc/preremove/base-files.sh

it provides defaults and sets them up in the postinstall script driven by the manifest.

In our case, the ancient Cygwin.bat was always installed with a hard-coded path by Cygwin setup and never replaced, by design!

I just updated it from /etc/defaults/ so it looks like your first version.

You could also rm /Cygwin.bat and rerun /etc/postinstall/base-files-profile.sh, possibly with a .done suffix after Setup.

For a portable setup, I am intending to remove and wrap Cygwin.bat and have _zero_ issue 
with Cygwin Setup restoring it (I was actually hoping Cygwin Setup _did_ restore 
Cygwin.bat so that any updates to Cygwin.bat could be incorporated), but the challenge 
here is that a completely different Cygwin.bat that contains hard-coded paths is created 
upon restoration.  Is this file content difference expected?  Could the `cd /d 
"%~dp0bin"` syntax be used in both cases (in place of the hardcoded paths)?

It has been and should be since at least 2016, when it was added to base-files; previously it was installed by Cygwin Setup and never updated if it existed:

        https://cygwin.com/cgit/cygwin-apps/setup/tree/desktop.cc?id=bf1d58#n163

[which is always a bad idea, as shown by the history of the single instruction program IEFBR14 which only returned to the IBM OS; until it needed to return 0, like `true`, after some system changes; then the assembler got stricter, so it needed overhead; and so on; see: https://en.wikipedia.org/wiki/IEFBR14
see also: https://www.miketaylor.org.uk/tech/oreilly/truenut.html ]

As reference, the Cygwin Setup --version is 2.934 an the arguments passed to 
Cygwin Setup are as follows (PortableRoot and ARCH are set by the wrapper batch 
file that facilitates portability):
` --no-admin --no-shortcuts --no-write-registry --no-replaceonreboot --package-manager --root 
"%PortableRoot%\Cygwin\arch-%ARCH%"  --local-package-dir 
"%PortableRoot%\Cygwin\packages" --wait`
--
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                -- Antoine de Saint-Exupéry

Reply via email to