Subject: Re: Changing exec's #! behavior
To: Andrew Brown <>
From: Robert Elz <kre@munnari.OZ.AU>
List: tech-kern
Date: 06/16/2000 19:15:44
    Date:        Thu, 15 Jun 2000 18:10:05 -0400
    From:        Andrew Brown <>
    Message-ID:  <>

  | that' interesting idea.  although i'd suggest that it really
  | *should* check for the closing quote, since otherwise things like
  |     #!/bin/echo '
  | won't work as they used to.

Yes, as I said, things that want a single arg, starting with a quote,
will break - things that want a single arg containing spaces, will
break too - both can be fixed:

	#!/bin/echo ''

would do what the one above used to, the awk usage I described
would need a "'" inserted (your sh example could presumably go
either way - leave it, or add the ').  (Both are also fairly rare
in practice I think).

I don't think checking for the closing quote is useful - if it has
to be at the end of the line, and no-where else counts, then the check is
easy, but the quote is useless (it adds nothing), if the closing quote
can come anywhere, then there needs to be a way to actually include
a quote in the arg string, and you're back to needing a generalised
escaping mechanism.

  | yep.  that works.  but if you download something and start editing it,
  | that will be one thing you'll have to change.

That's true - in some cases, no matter what happens, as there are
already apparently divergent practices with how #! is handled, and
people taking advantage of all of them.

An option is simply to change nothing, and leave NetBSD how it has
been forever (which is how #! has been since it was first put in BSD),
and blame breakage on those who decided to make changes.

  | i can't say whether it's changed or not (and not commenting on the
  | alleged crock), but it certainly protects people from making messes of
  | 47 symlinks that lead to a file, or symlinks that point to themselves.

The mechanism was (I haven't looked to see if it still is) simply to
count the symlinks passed - which certainly prevents the problems, but
also leads to total confusion, someone makes a symlink to a file that
can reference, and the symlink fails, because the path that worked just
happens to contain the max number of symlinks allowed.  With automounters
making symlink soup, it is really all just a mess.  A proper mechanism
would be to actually check for path loops, but that turns out to be
extroadinarily hard to do correctly, especially when you want to be able
to have a symlink that is ../path and where inside ../path there is
another symlink that is ../../whatever so your (current) .. gets traversed
multiple times - without there being a loop.


ps: your echo example is a bit contrived, as what is actually echoed
is "' script-filename\n" which is most likely not what was hoped...