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

Re: Bug#270868: Should not implement "test" builtin



On Thu, 09 Sep 2004 23:10:10 +0200, Clint Adams wrote:
>> Clause 10.4 doesn't tell script authors
>> not to use non-POSIX features of standalone programs.  Why should it?
>> The purpose of 10.4 is to promote the portability of scripts across
>> POSIX-compliant shells, not to promote the portability of scripts to
>> other distributions.
> 
> Now I question the significance you see in "standalone program".


The significance of a command being implemented as a standalone program
is that it works the same way no matter what shell it is called from.
So there is no need to prohibit scripts from using non-POSIX features
of standalone programs for the sake of promoting portability across
shells.

But some commands that exist as standalone programs are also built in
to some shells.  This tempts one to argue that scripts shouldn't use
non-POSIX features of POSIX-specified standalone programs either -- so
that the scripts will work with shells that happen to build those commands
in.

But this brings us back to the original claim of the "Sections 10.4 and
6.1 are inconsistent" thread which was that there is no limit to what
commands a shell can build in; so, even if a script uses only POSIX
features of all commands that POSIX mentions, there is no guarantee that
the script will run properly on all shells that conform to the POSIX
standard.

The question in that thread was: How do we fix this bug in policy?

The question in this thread (#270868) is: Why is posh going out of its way
to break scripts that use test -a when policy 10.4 doesn't prohibit the
use of non-POSIX features of standalone programs?  If you answer "Because
the test command could be built in by shells with only POSIX features"
then you have to answer the objection that this rationale isn't backed
up by policy; plus the objection that both bash and dash implement test -a.


>> The actual list of built-in utilities specified by POSIX[1] is:
>> 
>>     break, colon, continue, dot, eval, exec, exit, export, readonly,
>>     return, set, shift, times, trap, unset
>> 
>> 'test' is not on this list.
> 
> Neither is 'cd'.


Sorry for the oversight.  In addition to those I listed above ("special
built-in utilities") POSIX specifies the following "regular built-in
utilities":

    alias, bg, cd, command, false, fc, fg, getopts, jobs, kill, newgrp,
    pwd, read, true, umask, unalias, wait.

I neglected to include the latter list in my previous message.  The test
command isn't on this list either.


>> If the reasoning above is correct then this feature of posh imposes a
>> restriction on scripts that isn't warranted by policy.  If the purpose
>> of posh is to facilitate the testing of scripts' policy-compliance
>> then the "test" builtin should not be included.
> 
> Does that also apply to "break", "cd", "command", ":", "continue",
> ".", "echo", "eval", "exec", "exit", "export", "kill", "read",
> "readonly", "return", "set", "shift", "times", "trap", "ulimit",
> "unset", and "wait"?
> 
> If there are any of these that you feel should be removed along with
> "test", why shouldn't they be removed from all other shells as well?


All of the commands in your list are POSIX-required builtins with the
exception of: ":", "echo", and "ulimit".

The echo command is available as /bin/echo and isn't in the list of
builtins so it is in the same boat as the test command.  It should also be
removed from posh.

posh already doesn't implement ulimit so there is no question of removing
it.

Interestingly, that leaves ":".  There is no standalone ":" and I can't
find any mention of it in the POSIX document.  It seems that every
package containing a script that runs ":" has an RC bug.  ;)

-- 
Thomas Hood



Reply to: