Portable Cygwin: Hard-Coded Paths in a Restored Cygwin.bat File?

Matthew Sheets ms.github@outlook.com
Mon Aug 4 23:30:11 GMT 2025


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


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)?


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`


Thank you,
Matthew


More information about the Cygwin-apps mailing list