Ever need to run a command you know how to do very well in Ruby but don’t know off hand with bash? It’s pretty easy if you have a single line handy for ruby like:
$ ruby -e 'puts "hello!"'
But, what happens if the ruby code is more complex and has multiple lines? You can obviously use semi-colons, but that’s less elegant. Let me introduce you to bash heredocs. Here’s an example of uploading a file to S3 with the right_aws gem.
$ cat <<RUBIES | ruby > # Write my rubyies here! > require 'right_aws' > s3 = RightAws::S3.new('key', 'secret_key') > bucket = s3.bucket("my_awesome_bucket") > bucket.put("path/in/s3/my_large_file.csv", open('/path/to/local/file.csv', 'r')) > RUBIES