Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 1058796 - Add support for SCL in shebangs
Summary: Add support for SCL in shebangs
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: scl-utils
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jan Zeleny
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: 949833 1369788 1390495
TreeView+ depends on / blocked
 
Reported: 2014-01-28 14:36 UTC by Vít Ondruch
Modified: 2017-05-10 11:23 UTC (History)
6 users (show)

Fixed In Version: scl-utils-2.0.1-2.fc21
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1369788 (view as bug list)
Environment:
Last Closed: 2015-01-30 04:28:51 UTC


Attachments (Terms of Use)

Description Vít Ondruch 2014-01-28 14:36:16 UTC
Everybody would like to write scripts such as:

$ cat myscript.rb
#!/usr/bin/scl enable ruby193 ruby
puts 'hello from ruby'

However, this does not work. Therefore some tries to workaround this problem using wrapper scripts, so there exits package such as ruby193-ruby-wrapper, which add some simple wrappers you can later use in shebangs. Other fails with errors such as [1].

It appears, that all these problems are due to nature, of how the shebang is interpreted. E.g. the line "#!/usr/bin/scl enable ruby193 ruby" is the same as you would execute "/usr/bin/scl 'enable ruby193 ruby'". In other words, everything behind the /usr/bin/scl is passed into the newly executed interpreter as a first argument. How this works is discussed in [2].

I believe, that simple solution would be, if scl can parse the first parameter and split it internally into the other parameters, when it detects:

1) it has only one parameter,
2) it begins with acceptable keyword
3) and this keyword is followed by white space.

This IMO would completely remove the need for wrapper scripts and make scl users more happy.


[1] https://access.redhat.com/site/discussions/702583
[2] http://netbsd.2816.n7.nabble.com/usr-bin-env-behaviour-td219297.html

Comment 1 Miroslav Suchý 2014-01-28 16:50:28 UTC
Note that since bug 924120 you can use -- as delimiter, which can get you help rid of quotes:
/usr/bin/scl enable ruby193 -- ruby

But that does not solve the problem with shebang behaviour :(

I would not like modification of scl itself. Because it opens question how to parse options which contains spaces:
ruby -e puts\ "foo"
 
Instead we can ship with scl-utils script called scl-shebang, which will be:
#!/bin/bash
ACTION = $1
COLLECTION = $2
shift 2
scl "$ACTION" "$COLLECTION" $@

And you should be then able to run
#!/usr/bin/scl-shebang enable ruby193 -- ruby --some-param

Comment 2 Honza Horak 2014-01-28 17:41:15 UTC
(In reply to Miroslav Suchý from comment #1)
> Instead we can ship with scl-utils script called scl-shebang, which will be:
> #!/bin/bash
> ACTION = $1
> COLLECTION = $2
> shift 2
> scl "$ACTION" "$COLLECTION" $@
> 
> And you should be then able to run
> #!/usr/bin/scl-shebang enable ruby193 -- ruby --some-param

IIUIC, the script gets only $1 set to value 'enable ruby193 -- ruby --some-param' in this example, so it should have to look differently; e.g. like the following:

#!/bin/sh
eval scl $@

Anyway, +1 for additional script, since making scl more complex doesn't seem like a good idea for me.

Comment 3 Vít Ondruch 2014-01-29 08:19:39 UTC
Thank you guys for your input. Definitely good idea with scl-shebang wrapper.

Nevertheless, I am still slightly in favor of my original proposal for single reason - it does not need any additional documentation IMO. Using "#!/usr/bin/scl enable ruby193 ruby" shebang is naturally the first thing people will try and fail with confusing: "Need at least 3 arguments. Run scl --help to get help." So I would first try to modify the scl and if this attempt fails, I would go with something like scl-shebang.

Btw I agree with Honza's commet #2 (did not tested it though ;).

Comment 4 Jan Zeleny 2014-04-08 11:52:39 UTC
Upstream ticket:
https://fedorahosted.org/SoftwareCollections/ticket/13

Comment 5 Fedora Update System 2015-01-09 15:05:35 UTC
scl-utils-2.0-2.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/scl-utils-2.0-2.fc20

Comment 6 Fedora Update System 2015-01-09 15:06:45 UTC
scl-utils-2.0-2.fc21 has been submitted as an update for Fedora 21.
https://admin.fedoraproject.org/updates/scl-utils-2.0-2.fc21

Comment 7 Fedora Update System 2015-01-10 02:58:08 UTC
Package scl-utils-2.0-2.fc21:
* should fix your issue,
* was pushed to the Fedora 21 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing scl-utils-2.0-2.fc21'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2015-0479/scl-utils-2.0-2.fc21
then log in and leave karma (feedback).

Comment 8 Fedora Update System 2015-01-21 08:27:03 UTC
scl-utils-2.0.1-1.fc21 has been submitted as an update for Fedora 21.
https://admin.fedoraproject.org/updates/scl-utils-2.0.1-1.fc21

Comment 9 Fedora Update System 2015-01-21 08:27:22 UTC
scl-utils-2.0.1-1.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/scl-utils-2.0.1-1.fc20

Comment 10 Miroslav Suchý 2015-01-21 08:44:21 UTC
Can you please post here, what solution you choose? How this report was resolved?

Comment 11 Jan Zeleny 2015-01-21 09:41:50 UTC
This works as of scl-utils-2.0:

#!/usr/bin/scl enable <collection> -- <command>

If you find any problems, let us know.

Comment 12 Fedora Update System 2015-01-30 04:28:51 UTC
scl-utils-2.0.1-2.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 13 Fedora Update System 2015-01-30 04:44:21 UTC
scl-utils-2.0.1-2.fc21 has been pushed to the Fedora 21 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 14 iakov Gan 2016-06-26 18:19:45 UTC
Any idea when/how scl-utils-2.0.1 will be avalible for RHEL?

Comment 15 Vít Ondruch 2016-06-27 08:51:31 UTC
(In reply to iakov Gan from comment #14)
> Any idea when/how scl-utils-2.0.1 will be avalible for RHEL?

I would not expect it any time soon due to backward compatibility issues.


Note You need to log in before you can comment on or make changes to this bug.