If you need to run Ruby code from within a shell script, you could easily execute a Ruby script with a simple bash command. This means you will have two files – one bash script and one Ruby script.
However, what if you want to combine the two file into a single file?
Simple, using a heredoc in your bash script, we simply pass the entire heredoc to the ruby executable. Create a file called
hybrid which contains the following code:
#!/usr/bin/env sh echo "This is bash!" /usr/bin/env ruby <<-EORUBY puts 'This is ruby!' EORUBY
Running the above bash script will produce this:
$ . hybrid This is bash! This is ruby!
Hope this helps.