Skip to content

Instantly share code, notes, and snippets.

@kke
Last active February 17, 2017 08:29
Show Gist options
  • Save kke/c83a1fd00373b62e221e4ad279715872 to your computer and use it in GitHub Desktop.
Save kke/c83a1fd00373b62e221e4ad279715872 to your computer and use it in GitHub Desktop.
Ruby version requirement auto discovery wrapper / "conditional shebang"
#!/bin/sh
for ruby in $(which -a ruby); do
if $ruby -e "exit 1 if RUBY_VERSION < '2.1'"; then
exec $ruby -x "$0" "$@"
fi
done
echo "No suitable ruby 2.1+ interpreter found" >&2
exit 1
#!ruby
puts "Hey there from: #{RUBY_VERSION}"
puts "Because ruby -x skips until the first occurence of #!ruby"
puts "The ruby code here will be executed just fine"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment