Forum: Ruby shebang woes / syntax check weirdness?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Benjamin Andresen (Guest)
on 2006-05-14 16:21
(Received via mailing list)
Hello everyone, I just noticed that even though I call ruby form the
command line with a file as an argument it will execute the shebang
line.
Is this intentional behaviour? Because for me it doesn't hold to the
POLS.

I had a discussion with somebody about what should happen when you run
ruby with a file as an argument. We disagreed, so I didn't want to file
a bug right away, but hear some comments on the issue before. (I don't
know where to file bugs either. ;-)

From my perspective it should work the following way:

$ ruby myrubyfile.rb
It will run ruby and it ignores the shebang line (it starts with a #, so
it's clearly an comment.)

This doesn't work though, so if my shebang line is the following:
"#!/usr/bin/perl", it will run perl.
The same if you use "#!/bin/rm /etc/fstab" as your shebang line.
If would basically run the shebang line.

Obviously if you run your script the following way: ./myrubyfile.rb
this is fine and intended. Because it has to check the shebang line
to see how it has to be interpreted / executed.

Python on the other hand does it right... If I run:
$ python myrubyfile.rb
it will ignore the shebang line and try to interpret it.

perl shows the same behaviour as ruby... This also got me thinking if I
may be completely off.

I used this analogy in the discussion I had:

$ openoffice finances.doc
shouldn't run finances.doc because it has a shebang line, it should try
to read it.
So reading for an "editing" tool and interpreting for an interpreter
is the same thing in my opinion.

I noticed all this when I was doing ruby -c randomfile.pl to make some
vim(:make) stuff. Random file completion. :-)

...

In the end, who is right? Perl/Ruby or Python.

BR,
Ross B. (Guest)
on 2006-05-14 17:22
(Received via mailing list)
On Sun, 2006-05-14 at 21:19 +0900, Benjamin Andresen wrote:
>
>
> [...]
> In the end, who is right? Perl/Ruby or Python.

IMHO, Ruby and Perl have it right - recognising the shebang line means
any options there will be used - often you want options like -W or -K to
stay with the script in my experience (not to mention stuff like little
one-liner scripts using -n and so on).
Mike N. (Guest)
on 2006-05-14 20:17
Ross B. wrote:
> IMHO, Ruby and Perl have it right - recognising the shebang line means
> any options there will be used - often you want options like -W or -K to
> stay with the script in my experience (not to mention stuff like little
> one-liner scripts using -n and so on).

So does the shebang always over-ride settings that you have call to the
script like this,

$ ruby -W0 code.rb

where code.rb has,

#!/usr/bin/ruby -w
...

Seems to for me.
This topic is locked and can not be replied to.