I\'d like to run a long rsync command in Cygwin by double clicking on a .sh file in Windows. It must start in the file\'s containing directory (e.g. /cygdrive/c/scripts/) so th
I developed a .bat script on my own (not originated from other's answer) to associate a file type (e.g. *.cygwin) to open with this .bat, as follows:
=== file run-script-with-Cygwin-in-same-dir.bat ===
@echo off
REM Info: A script created by Johnny Wong. (last modified on 2014-7-15)
REM It is used to pass a file argument to run a bash script file. The current directory is setting to the path of the script file for convenience.
REM Could be copied to C:\cygwin; and then you manually associate .cygwin file extension to open with this .bat file.
set CYGWIN=nodosfilewarning
C:\cygwin\bin\bash --login -i -c 'cd "`dirname "%~1"`"; exec bash "%~1" %2 %3 %4 %5 %6 %7 %8 %9'
REM finally pause the script (press any key to continue) to keep the window to see result
pause
=== file run-script-with-Cygwin-in-same-dir.bat ===
Detail explanations on syntax used (if you are interested) :
for %%a in (%p%) do set p=%%~a
"%~1"
to force the script file's path double-quoted, so that its folder separators '\' (in %1) won't be removed by bash when being treated as escape characters. Otherwise, it does not work when dragging a file, which has no spaces in its path, to this .bat.Enjoys :)