wtnabe (owner)

Revisions

gist: 165860 Download_button fork
public
Public Clone URL: git://gist.github.com/165860.git
Embed All Files: show embed
which.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#! /usr/bin/env ruby
 
def which( cmd, *additional )
  paths = ENV['PATH'].split( File::PATH_SEPARATOR )
  paths += additional if additional
  path = paths.map { |d|
    file = File.join( d, cmd )
    ( File.exist?( file ) ) ? file : nil
  }.compact.first
 
  return ( path ) ? path : "command not found : #{cmd}"
end
 
puts which( ARGV[0], *ARGV[1..ARGV.size-1] )