Method: Chef::Sugar::Shell#which
- Defined in:
- lib/chef/sugar/shell.rb
#which(cmd) ⇒ String?
Finds a command in $PATH
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/chef/sugar/shell.rb', line 33 def which(cmd) if Pathname.new(cmd).absolute? File.executable?(cmd) ? cmd : nil else paths = ENV['PATH'].split(::File::PATH_SEPARATOR) + %w(/bin /usr/bin /sbin /usr/sbin) paths.each do |path| possible = File.join(path, cmd) return possible if File.executable?(possible) end nil end end |