From: Andrey Repin <anrdaemon@yandex.ru>
To: "Nellis, Kenneth" <Kenneth.Nellis@xerox.com>, cygwin@cygwin.com
Subject: Re: how to embed shell script within a .BAT file
Date: Tue, 11 Nov 2014 20:05:00 -0000 [thread overview]
Message-ID: <65830765.20141111225547@yandex.ru> (raw)
In-Reply-To: <0D835E9B9CD07F40A48423F80D3B5A702E839DB4@USA7109MB022.na.xerox.net>
Greetings, Nellis, Kenneth!
>> From: Achim Gratz
>>
>> Nellis, Kenneth writes:
>> > 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.
>>
>> The solution to the UNC path problem is to put something
>>
>> PUSHD %~dp0
>>
>> near the beginning of the script. That is if you really want to have .bat
>> files and click on them in Explorer. Associating the shell scripts
>> properly so that Explorer will hand them to Cygwin sounds like a better
>> solution to me.
> BTW, works great! Here's the completed .BAT file preface with added error
> handling so the CMD window doesn't auto-close if the bash code exits with
> an error.
> @echo off
> set PATH=C:\cygwin64\bin;%PATH%
> PUSHD %~dp0
PUSHD "%~dp0"
But be aware, that you will lose the ability to run such script from different
CWD.
> type %0 | sed "0,/^---BASH SCRIPT FOLLOWS---/ d; s/\r*$//" | bash
sed "0,/^---BASH SCRIPT FOLLOWS---/ d; s/\r*$//" < "%~f0" | bash
> if errorlevel 1 pause
> exit
That's nice for desktop application.
But
EXIT %ERRORLEVEL%
would be more useful in general.
And keep in mind: not everything can be run that way, unfortunately.
Only interpreters accepting command stream from STDIN (such as bash).
And you will lose the ability to pipe data to such script yourself.
> ---BASH SCRIPT FOLLOWS---
> ...
> I'll pursue associating a shell script with a file type
> when I have more time.
On a slightly unrelated note, please avoid naming your scripts ".bat", when
you are using extended CMD features. Not every .bat file interpreter supports
a full range of bugs in CMD.
--
WBR,
Andrey Repin (anrdaemon@yandex.ru) 11.11.2014, <22:35>
Sorry for my terrible english...
--
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
next prev parent reply other threads:[~2014-11-11 20:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-07 21:26 Nellis, Kenneth
2014-11-07 21:32 ` Eric Blake
2014-11-09 22:05 ` Andrey Repin
2014-11-07 21:48 ` Jeremy Bopp
2014-11-07 21:54 ` Eliot Moss
2014-11-10 14:49 ` Nellis, Kenneth
2014-11-10 18:09 ` Achim Gratz
2014-11-11 16:12 ` Nellis, Kenneth
2014-11-11 20:05 ` Andrey Repin [this message]
2014-11-10 19:05 ` Andrey Repin
2014-11-10 20:13 ` Andrew DeFaria
2014-11-10 21:05 ` Andrey Repin
2014-11-09 22:05 ` Andrey Repin
2014-11-10 0:35 ` Mike Brown
2014-11-10 2:20 ` Andrey Repin
2014-11-10 4:24 ` Mike Brown
2014-11-09 23:01 ` cyg Simple
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=65830765.20141111225547@yandex.ru \
--to=anrdaemon@yandex.ru \
--cc=Kenneth.Nellis@xerox.com \
--cc=cygwin@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).