This is the mail archive of the
cygwin
mailing list for the Cygwin project.
RE: how to embed shell script within a .BAT file
- From: "Nellis, Kenneth" <Kenneth dot Nellis at xerox dot com>
- To: "cygwin at cygwin dot com" <cygwin at cygwin dot com>
- Date: Mon, 10 Nov 2014 14:49:09 +0000
- Subject: RE: how to embed shell script within a .BAT file
- Authentication-results: sourceware.org; auth=none
- References: <545D3E21 dot 2030306 at bopp dot net>
> From: Jeremy Bopp
>
> On 11/07/2014 03:26 PM, Nellis, Kenneth wrote:
> > I'm tired of creating pairs of script files: a clickable .BAT file to
> > invoke my shell script and then my shell script to do the actual work.
> > I was wondering if any of the geniuses on this list have come up with
> > a way to embed a shell script inside a clickable .BAT file.
> Something like this might do. It assumes you know the path to the Cygwin
> bin directory. Passing in arguments would be a bit more work and would
> probably be somewhat limited unless you have a small number of possible
> arguments.
>
> FYI, I don't have a Windows system readily available anymore, so this is
> untested.
>
> Shelly.bat:
>
> @echo off
>
> rem Put Cygwin bin directory into PATH
> set PATH=C:\cygwin\bin;%PATH%
>
> type %0 | sed "0,/^---BASH SCRIPT FOLLOWS---/ d; s/\r*$//" | bash
> goto :eof
>
> ---BASH SCRIPT FOLLOWS---
> echo $SHELL is alive
> ^Z
Thanx to Jeremy, Andrey, and the others who responded.
Jeremy's solution is closest to what I was looking for; however
I need it to work from a networked, non-drive-mapped folder.
(CMD.EXE doesn't like UNC paths.) I hadn't realized that I could
pipe a script into bash.
Andrey also suggested something that allows Windows-clickable
script files, a strict requirement, bypassing the stated, but
unnecessary requirement that it be a .BAT file, by associating
a file type with bash. This would bypass the UNC issue, so may
end up being the best solution for me.
--Ken Nellis
--
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