Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - @echo off
 - rem shebang.bat - Unix shell behaviour from windows.
 - :: Use
 - :: assoc .=shebangfile
 - :: ftype shebangfile="c:\your\path\to\shebang.bat" "%1" "%*"
 - :: setx /M pathext %pathext%;.
 - rem Use setx so that the change is permanent though the effects will not happen until your next invocation of the shell (cmd.exe)
 - :: As of Window 8.x ftype requires a fully qualified path to the executable and it cannot
 - :: merely be on the path as it could in previous versions of Windows. Ms does not mention this in documentation though testing will
 - :: show that a fully qualified path is require. There example in help ftype will fail as documented.
 - :: All of these commands will require administrative privileges.
 - rem You will also need env.bat which can be found here: https://pastebin.com/aVrMnK8H or on the original author's website tutorial.
 - :: make sure the directory that env.bat is in is also in the system path.
 - rem You should visit the original Author's website for the full tutorial. Though the batch offered, at the time I posted this, has bugs
 - :: that have been fixed here.
 - rem Author: Dion Nicolaas <[email protected]>
 - :: http://whitescreen.nicolaas.net/programming/windows-shebangs
 - rem save filename
 - set filename=%1
 - rem Get the first line of the file
 - set /p line=<%1
 - rem Remove all quotes from the string, they shouldn't be there anyway
 - set line=%line:"=%
 - rem turn each part of the path into a quoted string, separated by spaces
 - set line="%line:/=" "%"
 - rem set first to the first part ("#!"), last to the last part (e.g. perl -w)
 - for %%i in (%line%) do call :firstlast %%i
 - rem if it was a shebang line, set command accordingly, else use "type"
 - set myCommand=type
 - if "%first%"=="#!" set myCommand=%last%
 - if "%first%"=="#! " set myCommand=%last%
 - rem Run command on the command line
 - if "%myCommand%"=="type" %myCommand% %filename%
 - if not "%myCommand%"=="type" %myCommand% %*
 - goto :EOF
 - :firstlast
 - rem Get first and last token, unquote in the process (which will also strip
 - :: spaces). In Unix scripts 'perl -w' is much more likely than "the language
 - :: processor" (long file name with spaces)
 - if "%first%"=="" set first=%~1
 - set last=%~1
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment