Created
February 10, 2013 23:00
-
-
Save sstephenson/4751426 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From: Sam Stephenson <[email protected]> | |
Subject: Re: ruby-build hint | |
Date: Sun, 10 Feb 2013 12:25:56 -0600 | |
To: Michał Papis <[email protected]> | |
Hi Michał, | |
Thanks for the email. | |
You're right that `[[` is not POSIX sh-compliant. Nor are the following | |
other constructs in ruby-build: | |
* String range operator (`"${arg:0:1}"`, `"${arg:1:1}"`, etc.) | |
* Arrays (`$OPTIONS`, `$words`, `$fetch_args`, `$make_args`) | |
* Variable indirection (`"${!PACKAGE_CONFIGURE_OPTS}"`, etc.) | |
* `declare -f` and `$FUNCNAME` | |
* `type` built-in | |
* stderr/stdout redirection using `&>/dev/null` | |
* Escaped character syntax (`$'\033'`) | |
And certainly there are more. These are just the ones I found making a | |
quick pass over the source code. | |
It's fine, though: ruby-build is a Bash program and doesn't claim to be | |
sh-compliant. Hence the explicit `#!/usr/bin/env bash` shebang. | |
As a rule I tend to prefer `[` to `[[` because the semantics are | |
simpler for me to remember, not because it is sh-compliant. In | |
particular, I prefer the way `[` behaves with `set -e`. In this | |
instance, I have made an exception because I find glob matching with | |
`[[` to be far less awkward and more readable than a single-clause | |
`case` statement. | |
cheers, | |
-sam | |
On Feb 9, 2013, at 11:30 PM, Michał Papis <[email protected]> wrote: | |
> Hi | |
> | |
> I thought making this an public ticket could be unappropriate those I | |
> mail you directly instead. | |
> | |
> I was just reading ruby-build code and found | |
> https://github.com/sstephenson/ruby-build/commit/3c6fa3901c89077697c9067d4de743bf37390c9c | |
> - so far the code all looked SH compatible (using '[' instead of | |
> '[[') but this change introduces '[['' which requires something more | |
> over pure SH code. | |
> | |
> You can easily replace this code with: | |
> | |
> [ "$(uname -s)" = "Darwin" ] && | |
> [ "$(openssl version 2>/dev/null || true)" = "OpenSSL 0.9.8r 8 Feb 2011" ] && | |
> case "$RUBY_CONFIGURE_OPTS" in | |
> *--with-openssl-dir=*) return 1;; | |
> esac | |
> | |
> which will make it back more pure SH. | |
> | |
> Cheers, | |
> Michal | |
> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment