bin/brew: always use [[ for consistency

This commit is contained in:
Xu Cheng 2016-01-18 11:40:00 +08:00
parent 29c50d2567
commit 3fdf1a623b

View File

@ -8,7 +8,7 @@ chdir() {
} }
# Force UTF-8 to avoid encoding issues for users with broken locale settings. # Force UTF-8 to avoid encoding issues for users with broken locale settings.
if [ "$(locale charmap 2> /dev/null)" != "UTF-8" ] if [[ "$(locale charmap 2> /dev/null)" != "UTF-8" ]]
then then
export LC_ALL="en_US.UTF-8" export LC_ALL="en_US.UTF-8"
fi fi
@ -16,7 +16,7 @@ fi
BREW_FILE_DIRECTORY="$(chdir "${0%/*}" && pwd -P)" BREW_FILE_DIRECTORY="$(chdir "${0%/*}" && pwd -P)"
HOMEBREW_BREW_FILE="$BREW_FILE_DIRECTORY/${0##*/}" HOMEBREW_BREW_FILE="$BREW_FILE_DIRECTORY/${0##*/}"
if [ -L "$HOMEBREW_BREW_FILE" ] if [[ -L "$HOMEBREW_BREW_FILE" ]]
then then
BREW_SYMLINK="$(readlink "$HOMEBREW_BREW_FILE")" BREW_SYMLINK="$(readlink "$HOMEBREW_BREW_FILE")"
BREW_SYMLINK_DIRECTORY="$(dirname "$BREW_SYMLINK")" BREW_SYMLINK_DIRECTORY="$(dirname "$BREW_SYMLINK")"
@ -30,7 +30,7 @@ HOMEBREW_LIBRARY="$(chdir "$BREW_FILE_DIRECTORY"/../Library && pwd -P)"
# Where we store built products; /usr/local/Cellar if it exists, # Where we store built products; /usr/local/Cellar if it exists,
# otherwise a Cellar relative to the Repository. # otherwise a Cellar relative to the Repository.
if [ -d "$HOMEBREW_PREFIX/Cellar" ] if [[ -d "$HOMEBREW_PREFIX/Cellar" ]]
then then
HOMEBREW_CELLAR="$HOMEBREW_PREFIX/Cellar" HOMEBREW_CELLAR="$HOMEBREW_PREFIX/Cellar"
else else
@ -43,7 +43,7 @@ case "$*" in
--repository|--repo) echo "$HOMEBREW_REPOSITORY"; exit 0 ;; --repository|--repo) echo "$HOMEBREW_REPOSITORY"; exit 0 ;;
esac esac
if [ "$HOMEBREW_PREFIX" = "/" ] || [ "$HOMEBREW_PREFIX" = "/usr" ] if [[ "$HOMEBREW_PREFIX" = "/" || "$HOMEBREW_PREFIX" = "/usr" ]]
then then
# it may work, but I only see pain this route and don't want to support it # it may work, but I only see pain this route and don't want to support it
echo "Cowardly refusing to continue at this prefix: $HOMEBREW_PREFIX" >&2 echo "Cowardly refusing to continue at this prefix: $HOMEBREW_PREFIX" >&2
@ -55,19 +55,19 @@ fi
unset GEM_HOME unset GEM_HOME
unset GEM_PATH unset GEM_PATH
if [ -z "$HOMEBREW_DEVELOPER" ] if [[ -z "$HOMEBREW_DEVELOPER" ]]
then then
unset HOMEBREW_RUBY_PATH unset HOMEBREW_RUBY_PATH
fi fi
if [ "$(uname -s)" = "Darwin" ] if [[ "$(uname -s)" = "Darwin" ]]
then then
HOMEBREW_OSX="1" HOMEBREW_OSX="1"
fi fi
if [ -z "$HOMEBREW_RUBY_PATH" ] if [[ -z "$HOMEBREW_RUBY_PATH" ]]
then then
if [ -n "$HOMEBREW_OSX" ] if [[ -n "$HOMEBREW_OSX" ]]
then then
HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
else else
@ -82,9 +82,9 @@ export HOMEBREW_REPOSITORY
export HOMEBREW_LIBRARY export HOMEBREW_LIBRARY
export HOMEBREW_CELLAR export HOMEBREW_CELLAR
if [ -n "$HOMEBREW_OSX" ] if [[ -n "$HOMEBREW_OSX" ]]
then then
if [ "$('xcode-select' --print-path)" = "/" ] if [[ "$('xcode-select' --print-path)" = "/" ]]
then then
cat >&2 <<EOS cat >&2 <<EOS
Your xcode-select path is currently set to '/'. Your xcode-select path is currently set to '/'.
@ -100,7 +100,7 @@ EOS
XCRUN_OUTPUT="$(/usr/bin/xcrun clang 2>&1)" XCRUN_OUTPUT="$(/usr/bin/xcrun clang 2>&1)"
XCRUN_STATUS="$?" XCRUN_STATUS="$?"
if [ "$XCRUN_STATUS" -ne 0 ] && [[ "$XCRUN_OUTPUT" = *license* ]] if [[ "$XCRUN_STATUS" -ne 0 && "$XCRUN_OUTPUT" = *license* ]]
then then
cat >&2 <<EOS cat >&2 <<EOS
You have not agreed to the Xcode license. Please resolve this by running: You have not agreed to the Xcode license. Please resolve this by running:
@ -112,7 +112,7 @@ fi
# Many Pathname operations use getwd when they shouldn't, and then throw # Many Pathname operations use getwd when they shouldn't, and then throw
# odd exceptions. Reduce our support burden by showing a user-friendly error. # odd exceptions. Reduce our support burden by showing a user-friendly error.
if ! [ -d "$(pwd)" ] if ! [[ -d "$(pwd)" ]]
then then
echo "The current working directory doesn't exist, cannot proceed." >&2 echo "The current working directory doesn't exist, cannot proceed." >&2
exit 1 exit 1
@ -128,7 +128,7 @@ fi
HOMEBREW_COMMAND="$1" HOMEBREW_COMMAND="$1"
HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/cmd/$1.sh" HOMEBREW_BASH_COMMAND="$HOMEBREW_LIBRARY/Homebrew/cmd/$1.sh"
if [ "$(id -u)" = "0" ] && [ "$(stat -f%u "$HOMEBREW_BREW_FILE")" != "0" ] if [[ "$(id -u)" = "0" && "$(stat -f%u "$HOMEBREW_BREW_FILE")" != "0" ]]
then then
case "$HOMEBREW_COMMAND" in case "$HOMEBREW_COMMAND" in
install|reinstall|postinstall|link|pin|unpin|update|update-bash|upgrade|create|migrate|tap|switch) install|reinstall|postinstall|link|pin|unpin|update|update-bash|upgrade|create|migrate|tap|switch)
@ -143,7 +143,7 @@ EOS
esac esac
fi fi
if [ -x "$HOMEBREW_BASH_COMMAND" ] if [[ -x "$HOMEBREW_BASH_COMMAND" ]]
then then
# source rather than executing directly to ensure the entire file is read into # source rather than executing directly to ensure the entire file is read into
# memory before it is run. This makes running a Bash script behave more like # memory before it is run. This makes running a Bash script behave more like