This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: How does one find "cygdrive path" in a Win ".bat" file (was Re: Bug in "startXwin.bat")


Here's how I do it in a little batch file that I put on
my USB pen drive:

It's in the attached .TXT file - you'll need to rename
it to .BAT

Note that this batch file will OVERWRITE your fstab so
please review it before installing and using it on your
system.

Basically, it lets me carry Cygwin on a USB stick and
it does not care what drive letter it's attached as.

Note also that USB sticks are slowwww, so it's just for
emergencies :-)

Ralph
@ECHO OFF
REM --------------------------------------------------------------------------
REM Batch file to start Cygwin on arbitrary drive letters

SETLOCAL
  FOR /F %%D IN ("%CD%") DO SET CYGDRIVE=%%~dD

REM -- Check if we've already modified the fstab for this drive letter
  IF "%CYGDRIVE%"=="%CYGWIN_DRIVE%" GOTO :DONE

REM -- Check if the original fstab has been backed up
  IF EXIST %CYGDRIVE%\cygwinTest\etc\fstab.original GOTO MAKEFSTAB
    copy %CYGDRIVE%\cygwinTest\etc\fstab %CYGDRIVE%\cygwinTest\etc\fstab.original

REM -- Set up the default fstab
:MAKEFSTAB
  echo # Custom fstab for removable media                  >  %CYGDRIVE%\cygwinTest\etc\fstab
  echo # See /cygwin/etc/fstab.original for defaults      >>  %CYGDRIVE%\cygwinTest\etc\fstab
  echo %CYGDRIVE%/cygwinTest     /        ntfs binary 0 0 >>  %CYGDRIVE%\cygwinTest\etc\fstab
  echo %CYGDRIVE%/cygwinTest/bin /usr/bin ntfs binary 0 0 >>  %CYGDRIVE%\cygwinTest\etc\fstab
  echo %CYGDRIVE%/cygwinTest/lib /usr/lib ntfs binary 0 0 >>  %CYGDRIVE%\cygwinTest\etc\fstab

rem -- Start up thedefault shell
  chdir %CYGDRIVE%\cygwinTest\bin
  bash --login -i

ENDLOCAL

:DONE

REM We're done with the local variables, but remember to set
REM a variable that tells us the drive Cygwin is running on

  SET CYGWIN_DRIVE=%CYGDRIVE%

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]