bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: spaces in the shebang interpreter path


From: Stephane Chazelas
Subject: Re: spaces in the shebang interpreter path
Date: Mon, 12 May 2008 17:20:25 +0100
User-agent: Mutt/1.5.16 (2007-09-19)

On Sun, May 11, 2008 at 02:01:29PM -0400, Paul Jarc wrote:
> Felix Schwarz <felix.schwarz@web.de> wrote:
> >         I'm not able to specify an interpreter in a shebang line if the path
> >         to this interpreter contains spaces.
> 
> It's actually the kernel that interprets that line, not bash.  The
> historical behavior is that space separates the interpreter from an
> optional argument, and there is no escape mechanism, so there's no way
> to specify an interpreter with a space in the path.  It's unlikely
> that this would ever change, since that would break existing scripts
> that rely on thecurrent behavior.
[...]

It should also be noted that the #! mechanism is not standard.
Read: not supported by either of the POSIX or Unix standard.

On POSIX systems, you can still use scripts, but either they are
considered as POSIX sh scripts (when they are called via
execvp/execlp(3) or sh(1) (and thus system(3)/popen(3))
env/awk/ex/vi... and all the standard utilities that can
execute commands) or you have to explicitely call the
interpreter (awk -f /path/the/file for instance).

Now, depending on the syntax of your interpreter, you could use
some trick to have your file interpreted by the proper
interpreter within those POSIX constraints.

For instance for awk, you could do thinks like:

"exec" "awk" "-f" "$0" "$@" && 0
<rest-of-your-awk-script-assuming-your-script-doesn't-have-only-BEGIN-statements>

-- 
Stéphane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]