#!ruby # == Synopsis # Copies files to stdout # # == Usage # ruby cat.rb file1 file2 ... filen # # == Author # Scott LaBounty # # == Copyright # Copyright(c) 2006 Scott LaBounty # # require 'getoptlong' require 'rdoc/usage' ## # Main Program # if __FILE__ == $0 # Set up the command line options opts = GetoptLong.new( ["--verbose", "-v", GetoptLong::NO_ARGUMENT], ["--help", "-h", GetoptLong::NO_ARGUMENT] ) # Set the default values for the options verbose = false date="" # Parse the command line options. If we find one we don't recognize # an exception will be thrown and we'll rescue with a RDoc::usage begin opts.each do | opt, arg| case opt when "--help" RDoc::usage when "--verbose" verbose = true end end rescue RDoc::usage end ARGV.each do | fileName | puts "fileName = #{fileName}" if verbose # Make sure the file exists if (File.exist?(fileName)) then # Open the file File.open(fileName) do | file | # For each line in the file file.each_line do | line | puts "#{line}" end end else puts "Could not find #{fileName}" end end end
You need to create an account or log in to post comments to this site.