# Shebang woes / syntax check weirdness?

**URL:** <https://www.ruby-forum.com/t/shebang-woes-syntax-check-weirdness/60476>\
**Category:** Ruby\
**Created:** [May 14, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/shebang-woes-syntax-check-weirdness/60476 "2006-05-14T14:21:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benjamin\_Andresen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c68b51/32.png) [@Benjamin\_Andresen](https://www.ruby-forum.com/u/Benjamin_Andresen)\
**Post date:** [May 14, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/shebang-woes-syntax-check-weirdness/60476/1 "2006-05-14T14:21:31Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![Benjamin\_Andresen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c68b51/32.png) [@Benjamin\_Andresen](https://www.ruby-forum.com/u/Benjamin_Andresen)\
**Post date:** [May 14, 2006, 3:22pm UTC](https://www.ruby-forum.com/t/shebang-woes-syntax-check-weirdness/60476/2 "2006-05-14T15:22:21Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Benjamin\_Andresen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c68b51/32.png) [@Benjamin\_Andresen](https://www.ruby-forum.com/u/Benjamin_Andresen)\
**Post date:** [May 14, 2006, 6:17pm UTC](https://www.ruby-forum.com/t/shebang-woes-syntax-check-weirdness/60476/3 "2006-05-14T18:17:23Z")

</div>

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.
