Guess what this will do...

J

John Carter

Without cheating (trying to run it) what will this pair of files do under Linux....

Here is a little script we want to be interpreted by the "flashbang" interpreter...
===/home/johnc/foo/hashbang===========================================
#!/home/johnc/foo/flashbang


puts ARGV[0]


======================================================================

So we expect
./hashbang "Hello World"
to be formally equivalent to running...

/home/johnc/foo/flashbang ./hashbang "Hello World"

Now assume....

===/home/johnc/foo/flashbang==========================================
#!/bin/sh

echo flashbanger
echo $0
echo "$@"

/usr/bin/ruby "$@"
======================================================================

Let's try...
/home/johnc/foo/flashbang -e 'puts "Hello World"'

On my system the result is....
flashbanger
/home/johnc/foo/flashbang
puts "Hello World"
Hello World

No surprise...

Now what do you think happens if you say...?

./hashbang "Hello World"

Now what do you think happens if you say....?

/home/johnc/foo/flashbang ./hashbang "Hello World"


Scroll down for the answers...
 
A

Anthony Martinez

--gmhhrsDozM2n+uz5
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Without cheating (trying to run it) what will this pair of files do under= Linux....
=20

[lots of stuff snipped]
WHAT THE HELL!? Why?
=20
Well, deep within ruby/ruby.c is a chunk of code that looks for a #!
on the first line. If it contains the word "ruby" anywhere, it ignores
it. If it doesn't it says, Oh dear. This one wasn't actually for me. I
better be gnice and exec that interpreter and feed it this script...
=20

That's a Perlism. man perlrun says:
If the #! line does not contain the word "perl", the program named
after the #! is executed instead of the Perl interpreter. This is
slightly bizarre, but it helps people on machines that don't do #!,
because they can tell a program that their SHELL is /usr/bin/perl,
and Perl will then dispatch the program to the correct interpreter
for them.

I'm a bit surprised that ruby mimicks this behavior! Does it even
_build_ on systems that don't do ``#!''?

All in all, you can tell I have a had rather exotic and frustrating
day or three.
=20
John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand
=20
=20

--=20
I saw `cout' being shifted "Hello world" times to the left and stopped right
there.
-- Steve Gonedes=20

--gmhhrsDozM2n+uz5
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFGgqQrKaiGM/xGKzQRAgj0AKDQPXJZg1BLJ51SvpIMat4tOsTORACfegi2
sACf21Slo3ZC+gekA+xQSvY=
=sFKG
-----END PGP SIGNATURE-----

--gmhhrsDozM2n+uz5--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top