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

Bug#999756: lintian: False positive bashism in posix shell after "exec"



Hi,

On Mon, Nov 15, 2021 at 10:06 PM Rafael Laboissière <rafael@debian.org> wrote:
>
> This is a false positive

I am not arguing, but wondered why the file did not just read like the
following:

>     #!/usr/bin/pltcl
>     source x00.tcl
>     plinit
>     x00
>     plend

For posterity, the answer was in the manual pages, starting with pltcl(1):

> It is essentially an extended tclsh

and then continuing in tclsh(1):

> If you create a Tcl script in a file whose first line is
>
>       #!/usr/local/bin/tclsh
>
> then you can invoke the script file directly from your shell if you
> mark the file as executable. This assumes that tclsh has been
> installed in the default location in /usr/local/bin; if it is
> sinstalled somewhere else then you will have to modify the above line
> to match. Many UNIX systems do not allow the #! line to exceed about
> 30 characters in length, so be sure that the tclsh executable can be
> accessed with a short file name.
>
> An even better approach is to start your script files with the following three lines:
>
>      #!/bin/sh
>      # the next line restarts using tclsh \
>      exec tclsh "$0" ${1+"$@"}
>
> This approach has three advantages over the approach in the previous
> paragraph. First, the location of the tclsh binary does not have to be
> hard-wired into the script: it can be anywhere in your shell search
> path. Second, it gets around the 30-character file name limit in the
> previous approach. Third, this approach will work even if tclsh is
> itself a shell script (this is done on some systems in order to handle
> multiple architectures or operating systems: the tclsh script selects
> one of several binaries to run). The three lines cause both sh and
> tclsh to process the script, but the exec is only executed by sh. sh
> processes the script first; it treats the second line as a comment and
> executes the third line. The exec statement cause the shell to stop
> processing and instead to start up tclsh to reprocess the entire
> script. When tclsh starts up, it treats all three lines as comments,
> since the backslash at the end of the second line causes the third
> line to be treated as part of the comment on the second line.

Kind regards
Felix Lechner


Reply to: