More Trivial Scripting with Ruby
Last Friday, in Trivial Scripting with Ruby on O'Reilly Ruby, Gregory Brown demonstrated a two-line example of the ease with which simple utility scripts can be created from Ruby. In his case a script that takes a filepath and returns the contents with all HTML entities escaped.
I like it, but I don't have any use for this operating on a per-file basis. More useful to me is being able to pass in the HTML text via command line args:
RUBY:
-
#!/usr/bin/env ruby
-
-
require "cgi"
-
ARGV.each { |x| puts CGI.escapeHTML( x ) }
I saved this as esc.rb. To use:
Sagarmatha:~/Documents/utilityscripts chris$ ./esc.rb "<em>Hello & World</em>"
<em>Hello & World</em>