Shebang (#!) fix.
Posted Wed, 01 Apr 2009
As an example, prior to today, I would have expected the following script to output 'debug: true'
#!/usr/bin/env ruby -d
puts "debug: #{$DEBUG}"
Running it, I get this:
% ./test.rb /usr/bin/env: ruby -d: No such file or directoryThis is because the 'program' executed is '/usr/bin/env' and the first argument passed is 'ruby -d', exactly as if you had run: /usr/bin/env "ruby -d"
My expectation was that the above would behave exactly like this:
% /usr/bin/env ruby -d test.rb debug: trueIt doesn't. The workaround, however, is pretty trivial. It's only a few lines of C to get me a program that works as I want. I call the program 'shebang'. Why is it C and not a script? Because most platforms have a requirement that the program being executed from the shebang line be a binary, not another script.
#!/usr/local/bin/shebang ruby -d
puts "debug: #{$DEBUG}"
Now run the script again, with our new shebang line:
% ./test.rb debug: trueSimple and works perfectly.