lkml.org 
[lkml]   [2016]   [May]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: script relative shebang
Date
Hi Boris,

Boris Rybalkin <ribalkin@gmail.com> writes:

> I would like to know if any changes to parsing '#!' script header line
> are accepted in particular having ability to run interpreter from
> relative to the script path?
>
> Something like:
>
> #!{dirname}/python/bin/python
>
> Where {dirname} is a special keyword replaced with dirname of a script.

Just for the record, this can already be done without any help from the
kernel:

Assuming the following demonstration directory layout

<some_test_dir>/subdir/catself
<some_test_dir>/relshebang

where catself.sh is your "interpreter":

#!/bin/sh
tail -n +2 $1

and relshebang is your script file invoking the toy interpreter from its
shebang as follows:

#!/usr/bin/gawk {exit system("/bin/sh -c 'exec \"$(dirname \"$0\")\"/subdir/catself \"$0\"' " FILENAME);}
Hello world.


You don't necessarily need to use gawk here, anything being able to do
system() and taking some code snippet from its first argument will
certainly work.

If this is too ugly, you could also write your own wrapper a la
/usr/bin/env and install that at some central location.


Best,

Nicolai

\
 
 \ /
  Last update: 2016-06-01 01:21    [W:0.116 / U:0.520 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site