From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756476AbcEaXCL (ORCPT ); Tue, 31 May 2016 19:02:11 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36589 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753673AbcEaXCJ (ORCPT ); Tue, 31 May 2016 19:02:09 -0400 From: Nicolai Stange To: Boris Rybalkin Cc: linux-kernel@vger.kernel.org Subject: Re: script relative shebang References: Date: Wed, 01 Jun 2016 01:02:05 +0200 In-Reply-To: (Boris Rybalkin's message of "Tue, 31 May 2016 22:47:52 +0100") Message-ID: <87lh2pj0gi.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.94 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Boris, Boris Rybalkin 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 /subdir/catself /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