Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15431

[PATCH] docs: More hints on #! parsing

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Eric Blake <eblake@redhat.com>
Newsgroups gnu.bash.bug
Subject [PATCH] docs: More hints on #! parsing
Date Wed, 25 Sep 2019 15:33:24 -0500
Lines 49
Approved bug-bash@gnu.org
Message-ID <mailman.1104.1569443616.2190.bug-bash@gnu.org> (permalink)
References <20190925203324.16276-1-eblake@redhat.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Transfer-Encoding quoted-printable
X-Trace usenet.stanford.edu 1569443616 23171 209.51.188.17 (25 Sep 2019 20:33:36 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
X-Scanned-By MIMEDefang 2.84 on 10.5.11.22
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Wed, 25 Sep 2019 20:33:24 +0000 (UTC)
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From 209.132.183.28
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.23
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <20190925203324.16276-1-eblake@redhat.com>
Xref csiph.com gnu.bash.bug:15431

Show key headers only | View raw


Just because Linux does not split whitespace on #! lines does not mean
that all operating systems behave the same.  Mention the recent
coreutils 8.30 'env -S' addition for working around interpreter
argument limitations, as well as the use of env to locate bash even
when it is not in /bin.

---
 doc/bashref.texi | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/doc/bashref.texi b/doc/bashref.texi
index 231356e5..53075c5c 100644
--- a/doc/bashref.texi
+++ b/doc/bashref.texi
@@ -3340,18 +3340,22 @@ an interpreter for the program.
 Thus, you can specify Bash, @code{awk}, Perl, or some other
 interpreter and write the rest of the script file in that language.

-The arguments to the interpreter
-consist of a single optional argument following the interpreter
-name on the first line of the script file, followed by the name of
-the script file, followed by the rest of the arguments.  Bash
-will perform this action on operating systems that do not handle it
-themselves.  Note that some older versions of Unix limit the interpreter
-name and argument to a maximum of 32 characters.
+The details of how the interpreter line is split depends on the
+operating system, then the result of that split is combined with the
+name of the script file and the rest of the command line arguments.
+Bash will perform this action on operating systems that do not handle
+it themselves.  Note that some older versions of Unix limit the
+interpreter name and a single argument to a maximum of 32 characters.
+For maximum portability, you must assume that the script can only
+embed a single optional argument following the interpreter name.  If
+your platform supports @code{env -S}, you can use that to work around
+the single argument limit.

 Bash scripts often begin with @code{#! /bin/bash} (assuming that
 Bash has been installed in @file{/bin}), since this ensures that
 Bash will be used to interpret the script, even if it is executed
-under another shell.
+under another shell.  Another common practice is the use of
+@code{#!/bin/env bash} to find the first instance of bash on @env{PATH}.

 @node Shell Builtin Commands
 @chapter Shell Builtin Commands
-- 
2.21.0

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

[PATCH] docs: More hints on #! parsing Eric Blake <eblake@redhat.com> - 2019-09-25 15:33 -0500

csiph-web