Bug 1478833

Summary: Ruby shebang interpreter misinterpretation
Product: Red Hat Software Collections Reporter: Joe Orton <jorton>
Component: rubyAssignee: ruby maint <ruby-maint>
Status: CLOSED CURRENTRELEASE QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rh-ruby24CC: pvalena, vondruch
Target Milestone: ---   
Target Release: 3.4   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-05 13:01:31 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Joe Orton 2017-08-07 09:01:59 UTC
Description of problem:
The Ruby executable interpreters the shebang line in a way which prevents use of ruby within a shebang, with the fixed scl for bug 1372700.  

Version-Release number of selected component (if applicable):
seen with all of ruby193/200/22/24

How reproducible:
always

Steps to Reproduce:
$ cat <<EOF > foo
> #!/usr/bin/scl enable rh-ruby22 -- ruby
> puts 'Hello, Brave New World.'
> EOF
$ chmod +x foo
$ ./foo 

Actual results:
/opt/rh/rh-ruby22/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- uby (LoadError) from
/opt/rh/rh-ruby22/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:54:in `require'

Expected results:
Hello, Brave New World

Additional info:
equivalent without scl enable fix, 
scl enable rh-ruby22 -- ruby < ./foo

.. has the same behaviour.

Comment 2 Vít Ondruch 2017-08-07 16:32:55 UTC
Actually, I can reproduce it on my Fedora without SCL:

~~~
$ cat <<EOF > foo
> #!/usr/bin/scl enable rh-ruby22 -- ruby
> EOF

$ ruby foo
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- uby (LoadError)
	from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:55:in `require'
~~~

So this is some misbehavior of Ruby parser it seems :/


$ rpm -q ruby
ruby-2.4.1-79.fc27.x86_64

Comment 6 Pavel Valena 2018-11-19 19:17:36 UTC
This is still an issue in both Ruby 2.3.8 and 2.4.5, but it's fixed in Ruby 2.5.

Comment 8 Joe Orton 2020-03-05 13:01:31 UTC
Confirmed this works with rh-ruby26 & rh-ruby27 at least - thanks!