[Top][All Lists]

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

bug#31215: coreutils env fails in a bash shebang

From: Eric Blake
Subject: bug#31215: coreutils env fails in a bash shebang
Date: Wed, 18 Apr 2018 22:11:01 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

tag 31215 notabug

On 04/18/2018 07:18 PM, William Schmidt wrote:
> I think I've found a bug in *coreutils*, *env*.
> Linux debian 4.9.0-4-amd64 #1 SMP Debian 4.9.65-3+deb9u1 (2017-12-23)
> x86_64 GNU/Linux
> All my Perl scripts contain either of these shebangs:
> #!/usr/bin/env perl -w
> or
> #!/usr/bin/env perl -wd

That is inherently non-portable.  On some operating systems (such as
GNU/Linux), the #! line is limited to EXACTLY ONE argument beyond the
name of the executable.  But you are trying to shoehorn two arguments
("perl" and "-w").  Just because it may have worked on some other
operating systems does not make it portable.

There may be ways to do what you want by telling perl to turn on -w or
-wd in subsequent lines of the script, or you can rewrite the #! line to
use /path/to/perl instead of trying to make env do the work.  Or perldoc
even includes some arcane formulas for using #!/bin/sh as the start, and
then exec into perl with as many desired arguments as you want
(including by using env to locate perl), as the first line when
interpreted by sh, while that exec line is skipped by perl.

But as this is a limitation of your operating system's handling of #!
and not a bug in env, there's nothing we can do about it in coreutils'
env.  So I'm closing this bug.

> Both of these shebangs work correctly in macOS 10.13.3 with the native perl
> from Apple and perlbrew perl. That is where I do most of my perl work but
> now I need to move those scripts to debian, without changing the shebangs.
> Is this a bug in *env*, something in bash or pilot error?

Pilot error, as you have used two different OS with different #!
handling rules.

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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