Proposal for new cygwin.bat which is independent from install directory

Bengt Larsson lists.cygwin4@bengtl.net
Sat Aug 27 16:20:00 GMT 2016


Christian Franke wrote:
>Bengt Larsson wrote:
>> -----
>> @echo off
>>
>> cd /d "%~dp0\bin"
>>
>> bash --login -i
>> -----
>
>An errorlevel check is IMO mandatory after a cd command. Otherwise 
>another bash in the PATH might be started if the directory does not exist.
>Hmm... therefore it is also better to change the last line to:
>
>   .\bash --login -i
>
>The directory change is intentionally done with two cd commands to avoid 
>possible problems with cmd variants 

>(on Win10 "%~dp0" expands to a path 
>with trailing backslash).

You're right although "%~dp0\subdir" still works (tested on Win10). An
easier way to test exit status is

  cd somedir || exit /b 1

With info for those who may not know the syntax:
-----
@echo off

rem %~dp0 is directory of this batch file

cd /d "%~dp0\bin" || exit /b 1

.\bash --login -i
-----

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list