Skip to content

Commit

Permalink
Use portable "command -v" to detect installed programs
Browse files Browse the repository at this point in the history
The "which" utility is not guaranteed to be installed either, and if it
is, its behavior is not portable either.

Conversely, the "command -v" shell builtin is required to exist in all
POSIX 2008 compliant shells, and is thus guaranteed to work everywhere.

Examples of open-source shells likely to be installed as /bin/sh on
Linux, which implement the 11-year-old standard: ash, bash, busybox,
dash, ksh, mksh and zsh.

See:
https://mywiki.wooledge.org/BashFAQ/081
https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then/85250#85250
  • Loading branch information
eli-schwartz committed Sep 2, 2020
1 parent 8e5ef45 commit 140fef7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/travis/tools/system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def description(*args)
def has?(command)
return false unless unix?
@has ||= {}
@has.fetch(command) { @has[command] = system "which #{command} 2>/dev/null >/dev/null" }
@has.fetch(command) { @has[command] = system "command -v #{command} 2>/dev/null >/dev/null" }
end

def running?(app)
Expand Down

0 comments on commit 140fef7

Please sign in to comment.