require "fileutils" f = File.open("hello.sh", "w") f.puts("#!/bin/bash") f.puts("echo Hello world!") f.close FileUtils.chmod(0755, "hello.sh")