delorie.com/archives/browse.cgi | search |
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:message-id:date:from:mime-version:to:subject | |
:references:in-reply-to:content-type; q=dns; s=default; b=dC8ZGo | |
TblJFmfrj0FFShJajXOttQqZi8NEbws7JV+rqLY/LC6dN54jiAijfZxieWh5ueCj | |
o3xxiuMpn+dkK9IIUsIHWlG2tyLF72kVFQlI8nJlbuF1yeY5zsQ1iy9zjMV604gS | |
4jzVSPU3abHjiJvHmz/+ZLNXjqbjmmiaww1G8= | |
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:message-id:date:from:mime-version:to:subject | |
:references:in-reply-to:content-type; s=default; bh=uHbR+WSbgLwQ | |
WoocnK8YaobJTk8=; b=k5X6DaB/fKrX69lhXbUZ7ZecG2ST6jk4bi7/9EXk7/SR | |
FeC1PSDMoj64j/ITPpZ9RG2NGOTL97D73GiozI+dW+VzP25T2rgNdV8TvcSHSgXH | |
AzzrFvndqnqg9FAGGRsZZZdWQLXfOtz+77nhejdiw8zmqchlXgjYme7ZnkB9oVk= | |
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-Spam-SWARE-Status: | No, score=-2.0 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 |
X-HELO: | etr-usa.com |
Message-ID: | <52F2D9AF.1060409@etr-usa.com> |
Date: | Wed, 05 Feb 2014 17:39:11 -0700 |
From: | Warren Young <warren AT etr-usa DOT com> |
User-Agent: | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 |
MIME-Version: | 1.0 |
To: | Andrey Repin <cygwin AT cygwin DOT com> |
Subject: | Re: Newbie Questions |
References: | <1898639722 DOT 6893470 DOT 1391541591920 DOT JavaMail DOT root AT ptd DOT net> <52F153AE DOT 5080704 AT gmail DOT com> <52F28215 DOT 5030801 AT ptd DOT net> <52F28330 DOT 6060101 AT cygwin DOT com> <52F2AA5D DOT 4000000 AT etr-usa DOT com> <52F2AD84 DOT 1050008 AT etr-usa DOT com> <709102296 DOT 20140206020738 AT mtu-net DOT ru> |
In-Reply-To: | <709102296.20140206020738@mtu-net.ru> |
X-IsSubscribed: | yes |
--------------010002060407050007080109 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 2/5/2014 15:07, Andrey Repin wrote: > >> But if you associate .sh with bash.exe, then double-click that script >> from Windows Explorer, it won't work right, since bash.exe will try to >> run it as a shell script. > > Have you actually tried that? Yep. > Try it, you'll be surprised. I did try it, before sending the previous message pair. Save the attached file as foo.sh, then run it with "bash foo.sh", rather than "./foo.sh". This is what happens when you associate *.sh with bash.exe in Windows Explorer. Bash tries to interpret the file as a shell script, despite the shebang line. This is because Bash doesn't do the shebang handling, exec() does, and Bash treats passed file names as names of shell scripts. It runs them directly, not through exec(). When you say "bash foo.sh" on the attached file, it complains: foo.sh: line 2: use: command not found Unable to initialize device PRN Then it sleeps for 2 seconds, since Bash and Perl both interpret line 4 the same way, if you ignore the minor semantic difference ";\n" makes to Bash. There is one small but critical difference in behavior when you do this by double-clicking foo.sh from Windows Explorer, with *.sh associated with Cygwin's bash.exe. That is, it only pauses on line 4 if your Cygwin bin directory is in the Windows system PATH, since otherwise, bash.exe can't find sleep.exe. Instead of adding Cygwin's bin directory to the Windows PATH, you can fix this with a minor registry hack. Open HKCU\Software\Classes\sh_auto_file\shell\open\command Change the default value to something like: "C:\cygwin32\bin\bash.exe" -l "%1" Adjust c:\cygwin32 as needed. This makes bash.exe a login shell, which forces it to run its startup scripts before running the script passed to it, so PATH gets set the same way it does for an interactive shell. This doesn't make bash.exe send foo.sh to perl.exe, though. To do that, you have to change the key's default value to: "C:\cygwin32\bin\bash.exe" -l -c 'exec `cygpath -u "%1"`' A registry hack that involves triply-nested quotes seems like a long way to go to make Windows Explorer run files the same way Bash would interactively. Plus, it only helps when you're attempting to deceive Bash. My motto: Don't lie to computers; they find ways to get even. --------------010002060407050007080109 Content-Type: application/x-shellscript; name="foo.sh" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="foo.sh" IyEvdXNyL2Jpbi9wZXJsCnVzZSB3YXJuaW5nczsKcHJpbnQgIkhlbGxvIGZy b20gUGVybCFcbiI7CnNsZWVwIDI7Cg== --------------010002060407050007080109 Content-Type: text/plain; charset=us-ascii -- 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 --------------010002060407050007080109--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |