type -P is more portable than which

Migrated from https://github.com/Linuxbrew/brew/pull/621
This commit is contained in:
Buck Evan 2018-03-17 23:02:05 -07:00 committed by Buck Evan (bukzor)
parent 63e8817950
commit 0a2e649f00
5 changed files with 13 additions and 13 deletions

View File

@ -114,10 +114,10 @@ EOS
if [[ -x "/usr/bin/shasum" ]] if [[ -x "/usr/bin/shasum" ]]
then then
sha="$(/usr/bin/shasum -a 256 "$CACHED_LOCATION" | cut -d' ' -f1)" sha="$(/usr/bin/shasum -a 256 "$CACHED_LOCATION" | cut -d' ' -f1)"
elif [[ -x "$(which sha256sum)" ]] elif [[ -x "$(type -P sha256sum)" ]]
then then
sha="$(sha256sum "$CACHED_LOCATION" | cut -d' ' -f1)" sha="$(sha256sum "$CACHED_LOCATION" | cut -d' ' -f1)"
elif [[ -x "$(which ruby)" ]] elif [[ -x "$(type -P ruby)" ]]
then then
sha="$(ruby <<EOSCRIPT sha="$(ruby <<EOSCRIPT
require 'digest/sha2' require 'digest/sha2'

View File

@ -85,10 +85,10 @@ fi
case "$(lowercase "$SCM_FILE")" in case "$(lowercase "$SCM_FILE")" in
git) git)
[[ -n "$HOMEBREW_GIT" ]] && safe_exec "$(which "$HOMEBREW_GIT")" "$@" [[ -n "$HOMEBREW_GIT" ]] && safe_exec "$(type -P "$HOMEBREW_GIT")" "$@"
;; ;;
svn) svn)
[[ -n "$HOMEBREW_SVN" ]] && safe_exec "$(which "$HOMEBREW_SVN")" "$@" [[ -n "$HOMEBREW_SVN" ]] && safe_exec "$(type -P "$HOMEBREW_SVN")" "$@"
;; ;;
esac esac
@ -99,7 +99,7 @@ brew_repo_version="$(quiet_safe_cd "$SCM_DIR/../../../../bin" && pwd -P)/$SCM_FI
safe_exec "$brew_repo_version" "$@" safe_exec "$brew_repo_version" "$@"
IFS=$'\n' IFS=$'\n'
for path in $(/usr/bin/which -a "$SCM_FILE" 2>/dev/null) for path in $(type -aP "$SCM_FILE")
do do
if [[ "$path" != "/usr/bin/$SCM_FILE" ]] if [[ "$path" != "/usr/bin/$SCM_FILE" ]]
then then

View File

@ -1,8 +1,8 @@
#!/bin/bash #!/bin/bash
POD2MAN="$(/usr/bin/which pod2man5.18 || POD2MAN="$(type -P pod2man5.18 ||
/usr/bin/which pod2man5.16 || type -P pod2man5.16 ||
/usr/bin/which pod2man5.12 || type -P pod2man5.12 ||
/usr/bin/which "$HOMEBREW_PREFIX/opt/pod2man/bin/pod2man" || type -P "$HOMEBREW_PREFIX/opt/pod2man/bin/pod2man" ||
echo /usr/bin/pod2man)" echo /usr/bin/pod2man)"
exec "$POD2MAN" "$@" exec "$POD2MAN" "$@"

View File

@ -39,13 +39,13 @@ _create_lock() {
local name="$2" local name="$2"
local ruby="/usr/bin/ruby" local ruby="/usr/bin/ruby"
local python="/usr/bin/python" local python="/usr/bin/python"
[[ -x "$ruby" ]] || ruby="$(which ruby 2>/dev/null)" [[ -x "$ruby" ]] || ruby="$(type -P ruby)"
[[ -x "$python" ]] || python="$(which python 2>/dev/null)" [[ -x "$python" ]] || python="$(type -P python)"
if [[ -x "$ruby" ]] && "$ruby" -e "exit(RUBY_VERSION >= '1.8.7')" if [[ -x "$ruby" ]] && "$ruby" -e "exit(RUBY_VERSION >= '1.8.7')"
then then
"$ruby" -e "File.new($lock_fd).flock(File::LOCK_EX | File::LOCK_NB) || exit(1)" "$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 then
flock -n "$lock_fd" flock -n "$lock_fd"
elif [[ -x "$python" ]] elif [[ -x "$python" ]]

View File

@ -32,7 +32,7 @@ setup-ruby-path() {
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
HOMEBREW_RUBY_PATH="$(which ruby)" HOMEBREW_RUBY_PATH="$(type -P ruby)"
fi fi
if [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] if [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]]