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

Portable scripting (was Re: traceroute /usr/bin -> /usr/sbin)



"Jacob Kuntz" <jpk@cape.com> writes:

> from the secret journal of Jakob 'sparky' Kaivo (jkaivo@elijah.nodomainname.net):
> > Also, using this syntax you can't pass flags to the interpreter
> > (eg. 'perl -w' wouldn't work).
> > 
> 
> [untested]
> 
> NAME
>        env - run a program in a modified environment
> 
> SYNOPSIS
>        env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]

It's not a limitation of env, it's a limitation of shebang
syntax. Script #! lines start with #! followed by the path to the
interpreter and optionally a single argument. Starting a script with

#!/usr/bin/env perl -w

would not work like

#!/usr/bin/perl -w

The kernel only passes the first argument to the interpreter. So, if
you have a script `foo' which starts with the env line, it is exec'd
as `/usr/bin/env perl foo', while the perl line would call
`/usr/bin/perl -w foo'. Maybe Perl is a poor choice, because I believe
the perl interpreter will scan the first line for additional switches
anyway, but many interpreters do not. Also, as pointed out elsewhere,
env is not always available in /usr/bin. There is no 100% portable way
of writing scripts apart from /bin/sh scripts apart from including a
README that basically says "Edit the file and put the right path on
line 1".

All that being said, this is a Debian list, so we need only be
concerned with scripts working on Debian systems. Policy already
describes how to write scripts for Debian.

-- sparky



Reply to: