delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/11/11/11:12:51

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:from:to:subject:date:message-id:references
:in-reply-to:content-type:content-transfer-encoding
:mime-version; q=dns; s=default; b=qFvSowGaZQDlUFLNz4D+swBq96XH/
BRFTJ4NFad/1bed4semw7mvX2THRl/wJ3ciji+2X9CHA144LCIi2ckmx+4IJihOY
eeB7gcHd9oiPoI3QkDK76aDly0Yw/1O31iBISlnOVFNRImOWdPwDqKQc1HyaOIuZ
Nlvirex1Jl1Fl4=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:from:to:subject:date:message-id:references
:in-reply-to:content-type:content-transfer-encoding
:mime-version; s=default; bh=YCtidtZR0AAR3ZitzbJ7f6fZhYs=; b=TNL
dg81V52iPrzCVZTUXrYQXKyhWgUfmTAW81OBQY4ag8mU4VN6FGwuKyA8tg7ncfXQ
jzxQihHlc46AIevYA4PcYYAuvr8WANWGmbBXjeMkc0fzWhQj1TUgX0R+v+xWcaZc
g9S45r4mbqCtOvPQYWnf8xfT8j6RX4CRDo3s09BA=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-0.2 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2
X-HELO: USA7109MR001.ACS-INC.COM
From: "Nellis, Kenneth" <Kenneth DOT Nellis AT xerox DOT com>
To: "cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Subject: RE: how to embed shell script within a .BAT file
Date: Tue, 11 Nov 2014 16:10:15 +0000
Message-ID: <0D835E9B9CD07F40A48423F80D3B5A702E839DB4@USA7109MB022.na.xerox.net>
References: <87bnoforlc DOT fsf AT Rainer DOT invalid>
In-Reply-To: <87bnoforlc.fsf@Rainer.invalid>
MIME-Version: 1.0
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id sABGClVu014247

> 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
type %0 | sed "0,/^---BASH SCRIPT FOLLOWS---/ d; s/\r*$//" | bash
if errorlevel 1 pause
exit

---BASH SCRIPT FOLLOWS---
...

I'll pursue associating a shell script with a file type
when I have more time.

--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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019