From 0a2e649f00deae00238f4ae700a6dc8d1829ae8c Mon Sep 17 00:00:00 2001 From: Buck Evan Date: Sat, 17 Mar 2018 23:02:05 -0700 Subject: [PATCH] `type -P` is more portable than `which` Migrated from https://github.com/Linuxbrew/brew/pull/621 --- Library/Homebrew/cmd/vendor-install.sh | 4 ++-- Library/Homebrew/shims/scm/git | 6 +++--- Library/Homebrew/shims/super/pod2man | 8 ++++---- Library/Homebrew/utils/lock.sh | 6 +++--- Library/Homebrew/utils/ruby.sh | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/cmd/vendor-install.sh b/Library/Homebrew/cmd/vendor-install.sh index 3b91dae5ca..8aba2174e5 100644 --- a/Library/Homebrew/cmd/vendor-install.sh +++ b/Library/Homebrew/cmd/vendor-install.sh @@ -114,10 +114,10 @@ EOS if [[ -x "/usr/bin/shasum" ]] then sha="$(/usr/bin/shasum -a 256 "$CACHED_LOCATION" | cut -d' ' -f1)" - elif [[ -x "$(which sha256sum)" ]] + elif [[ -x "$(type -P sha256sum)" ]] then sha="$(sha256sum "$CACHED_LOCATION" | cut -d' ' -f1)" - elif [[ -x "$(which ruby)" ]] + elif [[ -x "$(type -P ruby)" ]] then sha="$(ruby </dev/null) +for path in $(type -aP "$SCM_FILE") do if [[ "$path" != "/usr/bin/$SCM_FILE" ]] then diff --git a/Library/Homebrew/shims/super/pod2man b/Library/Homebrew/shims/super/pod2man index 90145766ff..1ad2cd2018 100755 --- a/Library/Homebrew/shims/super/pod2man +++ b/Library/Homebrew/shims/super/pod2man @@ -1,8 +1,8 @@ #!/bin/bash -POD2MAN="$(/usr/bin/which pod2man5.18 || - /usr/bin/which pod2man5.16 || - /usr/bin/which pod2man5.12 || - /usr/bin/which "$HOMEBREW_PREFIX/opt/pod2man/bin/pod2man" || +POD2MAN="$(type -P pod2man5.18 || + type -P pod2man5.16 || + type -P pod2man5.12 || + type -P "$HOMEBREW_PREFIX/opt/pod2man/bin/pod2man" || echo /usr/bin/pod2man)" exec "$POD2MAN" "$@" diff --git a/Library/Homebrew/utils/lock.sh b/Library/Homebrew/utils/lock.sh index e7fe348aa4..d8651cd754 100644 --- a/Library/Homebrew/utils/lock.sh +++ b/Library/Homebrew/utils/lock.sh @@ -39,13 +39,13 @@ _create_lock() { local name="$2" local ruby="/usr/bin/ruby" local python="/usr/bin/python" - [[ -x "$ruby" ]] || ruby="$(which ruby 2>/dev/null)" - [[ -x "$python" ]] || python="$(which python 2>/dev/null)" + [[ -x "$ruby" ]] || ruby="$(type -P ruby)" + [[ -x "$python" ]] || python="$(type -P python)" if [[ -x "$ruby" ]] && "$ruby" -e "exit(RUBY_VERSION >= '1.8.7')" then "$ruby" -e "File.new($lock_fd).flock(File::LOCK_EX | File::LOCK_NB) || exit(1)" - elif [[ -x "$(which flock 2>/dev/null)" ]] + elif [[ -x "$(type -P flock)" ]] then flock -n "$lock_fd" elif [[ -x "$python" ]] diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 2fb780c65a..e242cd6514 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -32,7 +32,7 @@ setup-ruby-path() { then HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" else - HOMEBREW_RUBY_PATH="$(which ruby)" + HOMEBREW_RUBY_PATH="$(type -P ruby)" fi if [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]]