# Hash banging #! - Distributing precompiled sharable linux bi

**URL:** <https://www.ruby-forum.com/t/hash-banging-distributing-precompiled-sharable-linux-bi/107988>\
**Category:** Ruby\
**Created:** [June 28, 2007, 4:58am UTC](https://www.ruby-forum.com/t/hash-banging-distributing-precompiled-sharable-linux-bi/107988 "2007-06-28T04:58:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [June 28, 2007, 4:58am UTC](https://www.ruby-forum.com/t/hash-banging-distributing-precompiled-sharable-linux-bi/107988/1 "2007-06-28T04:58:24Z")

</div>

This may, in a very odd set of circumstances, be useful to somebody…

If you try interpret a #! script with another #! script it fails. (I  
wrote about this problem before…)  
[http://tinyurl.com/287pez](http://tinyurl.com/287pez)

One fix is to use #!/usr/bin/env in the interpreted script, but  
doesn’t help you is you wish, as I did, to interpose something between  
lots and lots of #!/usr/bin/ruby scripts and ruby.

Here is another way, write a wee C program that does it for you…

In this case it wraps a ruby in an invocation of ld-linux.so.2 that  
loads up the copies of the latest libraries so a precompiled version  
will run on an old machine / distro…

// Autogenerated

#include \<unistd.h\>  
#include \<stdio.h\>  
#include \<stdlib.h\>

const char LD\_LINUX  
[]=“/opt/ruby/ruby-1.8.6-p36/dll\_hell-1.0/ld-linux.so.2”;  
const char DLL\_HELL []=“/opt/ruby/ruby-1.8.6-p36/dll\_hell-1.0”;  
const char BARE\_RUBY []=“/opt/ruby/ruby-1.8.6-p36/bin/.\_\_bare\_\_ruby”;  
/\* We’ve been called as…  
ruby arg\_1 arg\_2… arg\_argc-1

```
must call..
 ld-linux-so.2 --library-path dll_hell /opt/..../bare_ruby

```

\*/

int main( int argc, char \* argv[])  
{  
int i;  
int new\_argc = argc+3;  
const char \*\* new\_argv = (const char\*\*)malloc(  
sizeof(char\*)\*new\_argc + 1);

/\*  
printf(“argc=%d\n”,argc);  
for( i = 0; i \<= argc; ++i) {  
printf( “argv[%3d]=%s\n”,i, argv[i]);  
}  
\*/  
new\_argv[0] = “ruby”;  
new\_argv[1] = “–library-path”;  
new\_argv[2] = DLL\_HELL;  
new\_argv[3] = BARE\_RUBY;

```
for( i = 1; i <= argc; ++i) {
   new_argv[i+3] = argv[i];
}

```

/\*  
printf(“\nnew\_argc=%d\n”,new\_argc);  
for( i = 0; i \<= new\_argc; ++i) {  
printf( “new\_argv[%3d]=%s\n”,i, new\_argv[i]);  
}

\*/  
execv( LD\_LINUX, (char \* const \*)new\_argv);

```
perror( "Should haved execv'ed!");
return 1;

```

}

John C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
New Zealand

---

<div class="post-metadata">

**Author:** ![amin1426](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@amin1426](https://www.ruby-forum.com/u/amin1426)\
**Post date:** [June 28, 2007, 3:41pm UTC](https://www.ruby-forum.com/t/hash-banging-distributing-precompiled-sharable-linux-bi/107988/2 "2007-06-28T15:41:33Z")

</div>

Guess what. JRuby of all things runs into this problem[1], and they  
refuse bundle a fix.

Perhaps someone would also like to report this issue to the Linux-Kernel  
Mailing List, although it could be years before a fix sufficiently  
widespread in the wild for us to stop having to work around it.

–Ken

[1] [http://jira.codehaus.org/browse/JRUBY-1134](http://jira.codehaus.org/browse/JRUBY-1134)
