This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: How does one find "cygdrive path" in a Win ".bat" file (was Re: Bug in "startXwin.bat")
- From: Ralph Hempel <rhempel at bmts dot com>
- To: cygwin at cygwin dot com
- Date: Mon, 09 Feb 2009 20:30:07 -0500
- Subject: Re: How does one find "cygdrive path" in a Win ".bat" file (was Re: Bug in "startXwin.bat")
- References: <4990B031.4050807@tlinx.org> <4990B128.7030004@cygwin.com> <4990CB8D.3050704@tlinx.org> <4990D05A.4050202@cygwin.com>
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/