X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,TW_YG,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Message-ID: <4F7BC6B1.8030506@etr-usa.com> Date: Tue, 03 Apr 2012 21:57:37 -0600 From: Warren Young User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: Andrey Repin Subject: Re: Is this supposed to work this way? References: <0105D5C1E0353146B1B222348B0411A20A6536CB91 AT NIHMLBX02 DOT nih DOT gov> <602324786 DOT 20120404044708 AT mtu-net DOT ru> <4F7B9C81 DOT 4060209 AT redhat DOT com> <696106181 DOT 20120404053558 AT mtu-net DOT ru> In-Reply-To: <696106181.20120404053558@mtu-net.ru> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On 4/3/2012 7:35 PM, Andrey Repin wrote: > > what is the standard way of detecting OS type? > uname -o > ? The wise try not to do that at all. Instead, take in a little wisdom from the people who created autoconf, a piece of software that's been uncommonly successful[*] by FOSS standards: don't test for platforms, test for features. The reason is, platform feature sets change. When you write software that makes decisions based on platforms, it tends to break when those changes happen. Or, nearly as bad, your software continues to use some workaround that eventually becomes unnecessary when the platform fixes the problem that lead you to create the workaround. It's the latter case I'd worry about here. What's happening is that because you're launching the shell script through some Windows-native mechanism (double-clicking it in Explorer, maybe?) it's getting a Windows style path in $0. Maybe cygwin1.dll will one day detect that situation and translate the path automatically. The way I'd suggest you attack the problem is do a regex match on $0 to see if it looks like a Windows path, then run it through cygpath if so. "^[A-Z]:/" is probably a good enough test; it's unlikely to ever match a path your script gets on other platforms. A false positive would require that someone be *trying* to create an MS-DOS style path system on a *ix box, something far to ooky to believe has ever happened. But then, people are strange. Resist the temptation to back up the path style test with a platform test like the [ -f /bin/cygwin1.dll ] suggested by Barry. If the path looks like a Windows path, have the backbone to just send the path blindly through cygpath. If ever you run into a situation where cygpath doesn't exist but the path matches your regex, fix the regex or add a secondary feature test, don't resort to platform detection. [*] I think it's fair to say Autoconf's only real competition is ad hockery. -- 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