Last active
February 17, 2017 08:29
-
-
Save kke/c83a1fd00373b62e221e4ad279715872 to your computer and use it in GitHub Desktop.
Ruby version requirement auto discovery wrapper / "conditional shebang"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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