[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

shebang - what's the point?

Todd Burch

5/11/2007 2:43:00 PM

I've written a few hundred scripts now, and not once have I ever coded a
shebang line. I'm writing on both Windows and the Mac (Tiger).

Any time I'm kicking off a script from the Command Prompt or in Terminal
on the Mac, I simply type

ruby <name>.rb

and it works just fine.

So, when it comes down to it, what's the point of the shebang line?

Todd

--
Posted via http://www.ruby-....

11 Answers

Enrique Comba Riepenhausen

5/11/2007 2:49:00 PM

0

On 11 May 2007, at 16:43, Todd Burch wrote:

> I've written a few hundred scripts now, and not once have I ever
> coded a
> shebang line. I'm writing on both Windows and the Mac (Tiger).
>
> Any time I'm kicking off a script from the Command Prompt or in
> Terminal
> on the Mac, I simply type
>
> ruby <name>.rb
>
> and it works just fine.
>
> So, when it comes down to it, what's the point of the shebang line?
>
> Todd

Basically so that instead of

ruby <name>.rb

you can write

/<name>.rb

in the shell prompt.

Will only work in *NIX environments though (UNIX, LINUX, BSD, OS X,
Cygwin, etc.)

Cheers,

Enrique Comba Riepenhausen

Greg Donald

5/11/2007 2:51:00 PM

0

On 5/11/07, Todd Burch <promos@burchwoodusa.com> wrote:
> when it comes down to it, what's the point of the shebang line?


The shebang line makes scripts look and act similarly to regular executables.


--
Greg Donald
http://des...

Bill Guindon

5/11/2007 2:52:00 PM

0

On 5/11/07, Todd Burch <promos@burchwoodusa.com> wrote:
> I've written a few hundred scripts now, and not once have I ever coded a
> shebang line. I'm writing on both Windows and the Mac (Tiger).
>
> Any time I'm kicking off a script from the Command Prompt or in Terminal
> on the Mac, I simply type
>
> ruby <name>.rb
>
> and it works just fine.
>
> So, when it comes down to it, what's the point of the shebang line?

Unix/Linux and the Apache webserver (among others) use it to determine
how to execute the file. If you set the file to be executable (via
chmod), and it has the correct shebang line, you wouldn't need to type
'ruby', you could run it with just the filename.

> Todd
>
> --
> Posted via http://www.ruby-....
>
>


--
Bill Guindon (aka aGorilla)
The best answer to most questions is "it depends".

Sebastian Hungerecker

5/11/2007 2:58:00 PM

0

Todd Burch wrote:
> Any time I'm kicking off a script from the Command Prompt or in Terminal
> on the Mac, I simply type
>
> ruby <name>.rb
>
> and it works just fine.
>
> So, when it comes down to it, what's the point of the shebang line?

The point of the shebang line is not to have to tell the computer to open
the file with ruby. So you could write ./script or double click the script
in the file manager, even if it doesn't have the .rb-extension or the file
manager doesn't know how to open .rb-files.


--
Ist so, weil ist so
Bleibt so, weil war so

Todd Burch

5/11/2007 3:37:00 PM

0

OK, that all makes perfect sense. I figured there was a point, but in
my workflow, (work habits), I was not leveraging it.

Like my grandfather used to say - "if a man can't learn nothin' - he
ain't got no sense."

I learned something today! Thanks!
Todd

--
Posted via http://www.ruby-....

Christian Luginbuehl

5/11/2007 3:42:00 PM

0

> So, when it comes down to it, what's the point of the shebang line?

To summarize the to previous replies (Enrique and Greg):

Say you have a script that does some kind of sorting. You rename your

sort.rb file to sort

and give it the shebang line. If it's in the PATH you can simply run it
like:

$ sort testfile.txt

which I think is pretty neat.

As Enrique said before only *NIX environments support that.


Cheers,

Christian Luginbuehl

Daniel Martin

5/11/2007 6:04:00 PM

0

Todd Burch <promos@burchwoodusa.com> writes:

> So, when it comes down to it, what's the point of the shebang line?

There's one more advantage to using a #! line that applies when you're
posting a script in an email message -- in that case, you should begin
your script with

#!ruby

and end it with

__END__

If you do that, then people can save your email message to a file and
just run it with:

ruby -x email_message.txt

Regardless of what kind of headers or footers got attached to the
email message. (So long as email didn't word-wrap your script,
everything should be good)

--
s=%q( Daniel Martin -- martin@snowplow.org
puts "s=%q(#{s})",s.to_a.last )
puts "s=%q(#{s})",s.to_a.last

Todd Burch

5/11/2007 8:37:00 PM

0

Daniel Martin wrote:
> There's one more advantage to using a #! line that applies when you're
> posting a script in an email message -- in that case, you should begin
> your script with
>
> #!ruby
>
> and end it with
>
> __END__
>
> If you do that, then people can save your email message to a file and
> just run it with:
>
> ruby -x email_message.txt
>
> Regardless of what kind of headers or footers got attached to the
> email message. (So long as email didn't word-wrap your script,
> everything should be good)

I had absolutely no idea you could do that! How handy!!

Thanks!

--
Posted via http://www.ruby-....

Benjamin Kudria

5/11/2007 8:41:00 PM

0

On Friday, May 11 2007, Todd Burch wrote:
> So, when it comes down to it, what's the point of the shebang line?

I've always heard a slightly different, and in my opinion, logical
explanation.

Lets say you just got a new job as a sysadmin. The previous sysadmin was a
Perl guy, and since he was a good sysadmin, he used the shebang line in all
of his scripts , and he or she didn't add on the .pl .

Now, you come in, and seeing this Perl code, you scream and absolve to rewrite
it in Ruby, the cool kid on the block. After obtaining permission, you set
in and rewrite everything, and everything keeps working.

Now, imagine the same scenario, but no shebang line, and a .pl extension. If
you change the scripts, they won't work, because somewhere, someone is
running them with "perl myscript.pl", and myscript.pl will no longer exist,
or be a Perl script, after you are done with it.

So, shebang lines (and a lack of file extensions) are language-independent,
and future proof.

-Ben



Todd Burch

5/11/2007 8:51:00 PM

0

Benjamin Kudria wrote:

> So, shebang lines (and a lack of file extensions) are
> language-independent,
> and future proof.
>
> -Ben

An excellent reason to have them!

Todd

--
Posted via http://www.ruby-....